mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 16:23:36 +00:00

This helps to prevent issues where a failed test can keep a bound socket open long enough to cause other tests to fail with EADDRINUSE because the same port number is used. PR-URL: https://github.com/nodejs/node/pull/7045 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
38 lines
793 B
JavaScript
38 lines
793 B
JavaScript
'use strict';
|
|
// Serving up a zero-length buffer should work.
|
|
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var http = require('http');
|
|
|
|
var server = http.createServer(function(req, res) {
|
|
var buffer = Buffer.alloc(0);
|
|
// FIXME: WTF gjslint want this?
|
|
res.writeHead(200, {'Content-Type': 'text/html',
|
|
'Content-Length': buffer.length});
|
|
res.end(buffer);
|
|
});
|
|
|
|
var gotResponse = false;
|
|
var resBodySize = 0;
|
|
|
|
server.listen(0, function() {
|
|
http.get({ port: this.address().port }, function(res) {
|
|
gotResponse = true;
|
|
|
|
res.on('data', function(d) {
|
|
resBodySize += d.length;
|
|
});
|
|
|
|
res.on('end', function(d) {
|
|
server.close();
|
|
});
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.ok(gotResponse);
|
|
assert.equal(0, resBodySize);
|
|
});
|
|
|