2011-10-16 17:32:13 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var http = require('http');
|
|
|
|
|
2013-05-23 03:44:24 +02:00
|
|
|
var name = http.globalAgent.getName({ port: common.PORT });
|
2011-10-16 17:32:13 +02:00
|
|
|
var max = 3;
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
var server = http.Server(function(req, res) {
|
|
|
|
if (req.url === '/0') {
|
|
|
|
setTimeout(function() {
|
|
|
|
res.writeHead(200);
|
|
|
|
res.end('Hello, World!');
|
|
|
|
}, 100);
|
|
|
|
} else {
|
|
|
|
res.writeHead(200);
|
|
|
|
res.end('Hello, World!');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
for (var i = 0; i < max; ++i) {
|
|
|
|
request(i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function request(i) {
|
|
|
|
var req = http.get({
|
|
|
|
port: common.PORT,
|
|
|
|
path: '/' + i
|
|
|
|
}, function(res) {
|
|
|
|
var socket = req.socket;
|
|
|
|
socket.on('close', function() {
|
|
|
|
++count;
|
2011-11-29 12:55:05 +01:00
|
|
|
if (count < max) {
|
|
|
|
assert.equal(http.globalAgent.sockets[name].indexOf(socket), -1);
|
|
|
|
} else {
|
|
|
|
assert(!http.globalAgent.sockets.hasOwnProperty(name));
|
|
|
|
assert(!http.globalAgent.requests.hasOwnProperty(name));
|
2011-10-16 17:32:13 +02:00
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
2012-12-13 18:52:08 +01:00
|
|
|
res.resume();
|
2011-10-16 17:32:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(count, max);
|
|
|
|
});
|