You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

'use strict';
require('../common');
14 years ago
var assert = require('assert');
var http = require('http');
var body = 'hello world\n';
var headers = {'connection': 'keep-alive'};
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Length': body.length, 'Connection': 'close'});
res.write(body);
res.end();
});
14 years ago
var connectCount = 0;
server.listen(0, function() {
var agent = new http.Agent({ maxSockets: 1 });
var name = agent.getName({ port: this.address().port });
var request = http.request({
method: 'GET',
path: '/',
headers: headers,
port: this.address().port,
agent: agent
}, function(res) {
assert.equal(1, agent.sockets[name].length);
res.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
connectCount++;
});
});
request.end();
request = http.request({
method: 'GET',
path: '/',
headers: headers,
port: this.address().port,
agent: agent
}, function(res) {
assert.equal(1, agent.sockets[name].length);
res.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
connectCount++;
});
});
request.end();
request = http.request({
method: 'GET',
path: '/',
headers: headers,
port: this.address().port,
agent: agent
}, function(response) {
response.on('end', function() {
assert.equal(1, agent.sockets[name].length);
server.close();
});
response.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
connectCount++;
});
});
request.end();
});
process.on('exit', function() {
assert.equal(3, connectCount);
});