mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 03:31:35 +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>
55 lines
1.1 KiB
JavaScript
55 lines
1.1 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var http = require('http');
|
|
|
|
var agent = new http.Agent({
|
|
keepAlive: true,
|
|
keepAliveMsecs: 1000,
|
|
maxSockets: 2,
|
|
maxFreeSockets: 2
|
|
});
|
|
|
|
var server = http.createServer(function(req, res) {
|
|
res.end('hello world');
|
|
});
|
|
|
|
function get(path, callback) {
|
|
return http.get({
|
|
host: 'localhost',
|
|
port: server.address().port,
|
|
agent: agent,
|
|
path: path
|
|
}, callback);
|
|
}
|
|
|
|
var count = 0;
|
|
function done() {
|
|
if (++count !== 2) {
|
|
return;
|
|
}
|
|
var freepool = agent.freeSockets[Object.keys(agent.freeSockets)[0]];
|
|
assert.equal(freepool.length, 2,
|
|
'expect keep 2 free sockets, but got ' + freepool.length);
|
|
agent.destroy();
|
|
server.close();
|
|
}
|
|
|
|
server.listen(0, function() {
|
|
get('/1', function(res) {
|
|
assert.equal(res.statusCode, 200);
|
|
res.resume();
|
|
res.on('end', function() {
|
|
process.nextTick(done);
|
|
});
|
|
});
|
|
|
|
get('/2', function(res) {
|
|
assert.equal(res.statusCode, 200);
|
|
res.resume();
|
|
res.on('end', function() {
|
|
process.nextTick(done);
|
|
});
|
|
});
|
|
});
|