mirror of https://github.com/lukechilds/node.git
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.
44 lines
945 B
44 lines
945 B
9 years ago
|
'use strict';
|
||
|
const common = require('../common');
|
||
|
const assert = require('assert');
|
||
|
const http = require('http');
|
||
|
|
||
|
const MAX_SOCKETS = 2;
|
||
|
|
||
|
const agent = new http.Agent({
|
||
|
keepAlive: true,
|
||
|
keepAliveMsecs: 1000,
|
||
|
maxSockets: MAX_SOCKETS,
|
||
|
maxFreeSockets: 2
|
||
|
});
|
||
|
|
||
|
const server = http.createServer(function(req, res) {
|
||
|
res.end('hello world');
|
||
|
});
|
||
|
|
||
|
function get(path, callback) {
|
||
|
return http.get({
|
||
|
host: 'localhost',
|
||
|
port: common.PORT,
|
||
|
agent: agent,
|
||
|
path: path
|
||
|
}, callback);
|
||
|
}
|
||
|
|
||
|
server.listen(common.PORT, function() {
|
||
|
var finished = 0;
|
||
|
const num_requests = 6;
|
||
|
for (var i = 0; i < num_requests; i++) {
|
||
|
const request = get('/1', function() {
|
||
|
});
|
||
|
request.on('response', function() {
|
||
|
request.abort();
|
||
|
const sockets = agent.sockets[Object.keys(agent.sockets)[0]];
|
||
|
assert(sockets.length <= MAX_SOCKETS);
|
||
|
if (++finished === num_requests) {
|
||
|
server.close();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|