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.
52 lines
1.2 KiB
52 lines
1.2 KiB
14 years ago
|
var common = require('../common');
|
||
|
var http = require('http');
|
||
|
var assert = require('assert');
|
||
|
|
||
|
var N = 20;
|
||
|
var responses = 0;
|
||
|
var maxQueued = 0;
|
||
|
|
||
14 years ago
|
var agent = http.globalAgent;
|
||
14 years ago
|
agent.maxSockets = 10;
|
||
|
|
||
13 years ago
|
var server = http.createServer(function(req, res) {
|
||
14 years ago
|
res.writeHead(200);
|
||
|
res.end('Hello World\n');
|
||
|
});
|
||
|
|
||
12 years ago
|
var addrString = agent.getName({ host: '127.0.0.1', port: common.PORT });
|
||
13 years ago
|
|
||
13 years ago
|
server.listen(common.PORT, '127.0.0.1', function() {
|
||
14 years ago
|
for (var i = 0; i < N; i++) {
|
||
|
var options = {
|
||
|
host: '127.0.0.1',
|
||
13 years ago
|
port: common.PORT
|
||
14 years ago
|
};
|
||
|
|
||
|
var req = http.get(options, function(res) {
|
||
|
if (++responses == N) {
|
||
|
server.close();
|
||
|
}
|
||
12 years ago
|
res.resume();
|
||
14 years ago
|
});
|
||
|
|
||
|
assert.equal(req.agent, agent);
|
||
|
|
||
13 years ago
|
console.log('Socket: ' + agent.sockets[addrString].length + '/' +
|
||
|
agent.maxSockets + ' queued: ' + (agent.requests[addrString] ?
|
||
12 years ago
|
agent.requests[addrString].length : 0));
|
||
13 years ago
|
|
||
|
var agentRequests = agent.requests[addrString] ?
|
||
13 years ago
|
agent.requests[addrString].length : 0;
|
||
14 years ago
|
|
||
13 years ago
|
if (maxQueued < agentRequests) {
|
||
|
maxQueued = agentRequests;
|
||
14 years ago
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
process.on('exit', function() {
|
||
|
assert.ok(responses == N);
|
||
|
assert.ok(maxQueued <= 10);
|
||
|
});
|