Commit 2f91bc366d8 for nodejs
commit 2f91bc366d84498d5193156d72cda88b568583a9
Author: Filip Skokan <panva.ip@gmail.com>
Date: Wed Oct 21 09:32:56 2026 +0200
test: deflake test-http-agent-keepalive
The cleanup assertions can run before the socket closes when I/O is
delayed. Wait for the socket's close event in both the remote-close and
remote-error paths.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66887
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
diff --git a/test/parallel/test-http-agent-keepalive.js b/test/parallel/test-http-agent-keepalive.js
index ca50fa40bf2..48596e6caeb 100644
--- a/test/parallel/test-http-agent-keepalive.js
+++ b/test/parallel/test-http-agent-keepalive.js
@@ -94,13 +94,13 @@ function remoteClose() {
assert.strictEqual(agent.sockets[name], undefined);
assert.strictEqual(agent.freeSockets[name].length, 1);
assert.strictEqual(agent.totalSocketCount, 1);
- // Waiting remote server close the socket
- setTimeout(common.mustCall(() => {
+ // Wait for the remote server to close the socket.
+ req.socket.once('close', common.mustCall(() => {
assert.strictEqual(agent.sockets[name], undefined);
assert.strictEqual(agent.freeSockets[name], undefined);
assert.strictEqual(agent.totalSocketCount, 0);
remoteError();
- }), common.platformTimeout(200));
+ }));
}));
}));
}));
@@ -115,13 +115,13 @@ function remoteError() {
assert.strictEqual(agent.sockets[name].length, 1);
assert.strictEqual(agent.freeSockets[name], undefined);
assert.strictEqual(agent.totalSocketCount, 1);
- // Wait socket 'close' event emit
- setTimeout(common.mustCall(() => {
+ // Wait for the socket's 'close' event.
+ req.socket.once('close', common.mustCall(() => {
assert.strictEqual(agent.sockets[name], undefined);
assert.strictEqual(agent.freeSockets[name], undefined);
assert.strictEqual(agent.totalSocketCount, 0);
server.close();
- }), common.platformTimeout(1));
+ }));
}));
}