mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 11:29:26 +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>
45 lines
891 B
JavaScript
45 lines
891 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var http = require('http');
|
|
|
|
var body = 'hello world\n';
|
|
|
|
function test(headers) {
|
|
var server = http.createServer(function(req, res) {
|
|
console.error('req: %s headers: %j', req.method, headers);
|
|
res.writeHead(200, headers);
|
|
res.end();
|
|
server.close();
|
|
});
|
|
|
|
var gotEnd = false;
|
|
|
|
server.listen(0, function() {
|
|
var request = http.request({
|
|
port: this.address().port,
|
|
method: 'HEAD',
|
|
path: '/'
|
|
}, function(response) {
|
|
console.error('response start');
|
|
response.on('end', function() {
|
|
console.error('response end');
|
|
gotEnd = true;
|
|
});
|
|
response.resume();
|
|
});
|
|
request.end();
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.ok(gotEnd);
|
|
});
|
|
}
|
|
|
|
test({
|
|
'Transfer-Encoding': 'chunked'
|
|
});
|
|
test({
|
|
'Content-Length': body.length
|
|
});
|