diff options
author | fengmk2 <fengmk2@gmail.com> | 2015-03-23 19:33:13 +0800 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2015-04-17 12:20:44 -0400 |
commit | 7956a13dad02b47d3b61b593b5f25055372ce93c (patch) | |
tree | ddd2e8a615fbe808423fc3ea8dcd14e1dc27af59 /test/parallel/test-http-agent-maxsockets.js | |
parent | cd60ff03281a7e5a2cf0f7a2349303f1d44bb778 (diff) | |
download | android-node-v8-7956a13dad02b47d3b61b593b5f25055372ce93c.tar.gz android-node-v8-7956a13dad02b47d3b61b593b5f25055372ce93c.tar.bz2 android-node-v8-7956a13dad02b47d3b61b593b5f25055372ce93c.zip |
http: logically respect maxSockets
Allows the number of pooled free sockets to equal maxSockets.
Previously it would only allow maxSockets - 1.
PR-URL: https://github.com/iojs/io.js/pull/1242
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Christian Tellnes <christian@tellnes.no>
Diffstat (limited to 'test/parallel/test-http-agent-maxsockets.js')
-rw-r--r-- | test/parallel/test-http-agent-maxsockets.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/parallel/test-http-agent-maxsockets.js b/test/parallel/test-http-agent-maxsockets.js new file mode 100644 index 0000000000..0f349eac54 --- /dev/null +++ b/test/parallel/test-http-agent-maxsockets.js @@ -0,0 +1,53 @@ +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); + +var agent = new http.Agent({ + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 2, + maxFreeSockets: 2 +}); + +var 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); +} + +var count = 0; +function done() { + if (++count !== 2) { + return; + } + var freepool = agent.freeSockets[Object.keys(agent.freeSockets)[0]]; + assert.equal(freepool.length, 2, + 'expect keep 2 free sockets, but got ' + freepool.length); + agent.destroy(); + server.close(); +} + +server.listen(common.PORT, function() { + get('/1', function(res) { + assert.equal(res.statusCode, 200); + res.resume(); + res.on('end', function() { + process.nextTick(done); + }); + }); + + get('/2', function(res) { + assert.equal(res.statusCode, 200); + res.resume(); + res.on('end', function() { + process.nextTick(done); + }); + }); +}); |