Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
rickyes committed May 29, 2020
commit 5dffb12f222cfa1fdb0d5c7ec2060630dd70f894
2 changes: 1 addition & 1 deletion lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function Agent(options) {
validateNumber(this.maxTotalSockets, 'maxTotalSockets');
if (this.maxTotalSockets <= 0)
Comment thread
rickyes marked this conversation as resolved.
Outdated
throw new ERR_OUT_OF_RANGE('maxTotalSockets', '> 0',
this.maxTotalSockets);
this.maxTotalSockets);
} else {
this.maxTotalSockets = Infinity;
}
Expand Down
28 changes: 21 additions & 7 deletions test/parallel/test-http-agent-maxtotalsockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ const Countdown = require('../common/countdown');
const maxTotalSockets = 3;
const maxSockets = 2;

assert.throws(() => new http.Agent({
maxTotalSockets: 'test',
}), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "maxTotalSockets" argument must be of type number. ' +
"Received type string ('test')",
});

assert.throws(() => new http.Agent({
maxTotalSockets: -1,
Comment thread
rickyes marked this conversation as resolved.
Outdated
}), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "maxTotalSockets" is out of range. ' +
'It must be > 0. Received -1',
});

const agent = new http.Agent({
keepAlive: true,
keepAliveMsecs: 1000,
Expand Down Expand Up @@ -41,20 +59,16 @@ function handler() {
assert.strictEqual(res.statusCode, 200);
res.resume();
res.on('end', common.mustCall(() => {
testMaxSockets();
for (const key of Object.keys(agent.sockets)) {
assert(agent.sockets[key].length <= maxSockets);
}
assert(getTotalSocketsCount() <= maxTotalSockets);
countdown.dec();
}));
}));
}
}

function testMaxSockets() {
for(const key of Object.keys(agent.sockets)) {
assert(agent.sockets[key].length <= maxSockets)
}
}

function getTotalSocketsCount() {
let num = 0;
for (const key of Object.keys(agent.sockets)) {
Expand Down