Skip to content

Commit

Permalink
http: add tests for http agent totalSocketCount
Browse files Browse the repository at this point in the history
  • Loading branch information
jodevsa committed Oct 23, 2021
1 parent ced518c commit d50c671
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/parallel/test-http-agent-keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function checkDataAndSockets(body) {
assert.strictEqual(body.toString(), 'hello world');
assert.strictEqual(agent.sockets[name].length, 1);
assert.strictEqual(agent.freeSockets[name], undefined);
assert.strictEqual(agent.totalSocketCount, 1);
}

function second() {
Expand All @@ -73,6 +74,7 @@ function second() {
process.nextTick(common.mustCall(() => {
assert.strictEqual(agent.sockets[name], undefined);
assert.strictEqual(agent.freeSockets[name].length, 1);
assert.strictEqual(agent.totalSocketCount, 0);
remoteClose();
}));
}));
Expand All @@ -91,6 +93,7 @@ function remoteClose() {
process.nextTick(common.mustCall(() => {
assert.strictEqual(agent.sockets[name], undefined);
assert.strictEqual(agent.freeSockets[name].length, 1);
assert.strictEqual(agent.totalSocketCount, 0);
// Waiting remote server close the socket
setTimeout(common.mustCall(() => {
assert.strictEqual(agent.sockets[name], undefined);
Expand All @@ -110,10 +113,12 @@ function remoteError() {
assert.strictEqual(err.message, 'socket hang up');
assert.strictEqual(agent.sockets[name].length, 1);
assert.strictEqual(agent.freeSockets[name], undefined);
assert.strictEqual(agent.totalSocketCount, 0);
// Wait socket 'close' event emit
setTimeout(common.mustCall(() => {
assert.strictEqual(agent.sockets[name], undefined);
assert.strictEqual(agent.freeSockets[name], undefined);
assert.strictEqual(agent.totalSocketCount, -1);
server.close();
}), common.platformTimeout(1));
}));
Expand All @@ -132,6 +137,7 @@ server.listen(0, common.mustCall(() => {
process.nextTick(common.mustCall(() => {
assert.strictEqual(agent.sockets[name], undefined);
assert.strictEqual(agent.freeSockets[name].length, 1);
assert.strictEqual(agent.totalSocketCount, 0);
second();
}));
}));
Expand Down

0 comments on commit d50c671

Please sign in to comment.