This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #877. Don't wait for socket pool to establish connections.
Thanks to Yann Biancheri for putting together an initial test.
- Loading branch information
Showing
2 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var common = require('../common'); | ||
var http = require('http'); | ||
var assert = require('assert'); | ||
|
||
var N = 20; | ||
var responses = 0; | ||
var maxQueued = 0; | ||
|
||
debugger; | ||
|
||
var agent = http.getAgent('127.0.0.1', common.PORT); | ||
agent.maxSockets = 10; | ||
|
||
var server = http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.end('Hello World\n'); | ||
}); | ||
|
||
server.listen(common.PORT, "127.0.0.1", function() { | ||
for (var i = 0; i < N; i++) { | ||
var options = { | ||
host: '127.0.0.1', | ||
port: common.PORT, | ||
}; | ||
|
||
debugger; | ||
|
||
var req = http.get(options, function(res) { | ||
if (++responses == N) { | ||
server.close(); | ||
} | ||
}); | ||
|
||
assert.equal(req.agent, agent); | ||
|
||
console.log('Socket: ' + agent.sockets.length + | ||
'/' + agent.maxSockets + | ||
' queued: '+ agent.queue.length); | ||
|
||
if (maxQueued < agent.queue.length) { | ||
maxQueued = agent.queue.length; | ||
} | ||
} | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.ok(responses == N); | ||
assert.ok(maxQueued <= 10); | ||
}); |