test: improve sequential test performance

Make a couple of sequential tests clean up eagerly
to reduce runtime.

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65928
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
James M Snell authored and Antoine du Hamel committed 2026-09-16 21:12:15 +02:00
1 parent c518831d00
commit fa19ecad9d
2 files changed
+8 -8

No files matched your search

@@ -32,7 +32,7 @@ let rounds = 1;
let reqs = 0;
let port;
const server = net.createServer().listen(0, common.mustCall(() => {
const server = net.createServer().listen(0, common.localhostIPv4, common.mustCall(() => {
port = server.address().port;
server.close(common.mustCall(pummel));
}));
@@ -40,17 +40,14 @@ const server = net.createServer().listen(0, common.mustCall(() => {
function pummel() {
let pending;
for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) {
net.createConnection({ port, autoSelectFamily: false }).on('error', common.mustCallAtLeast((error) => {
// Family autoselection might be skipped if only a single address is returned by DNS.
const actualError = Array.isArray(error.errors) ? error.errors[0] : error;
net.createConnection({ host: common.localhostIPv4, port }).on('error', common.mustCall((error) => {
console.log('pending', pending, 'rounds', rounds);
assert.strictEqual(actualError.code, 'ECONNREFUSED');
assert.strictEqual(error.code, 'ECONNREFUSED');
if (--pending > 0) return;
if (rounds === ROUNDS) return check();
rounds++;
pummel();
}, 0));
}));
reqs++;
}
}
+4 -1
View File
@@ -93,7 +93,10 @@ function startClient() {
port: common.PORT,
method: 'GET',
path: '/',
headers: { 'content-length': buffer.length },
headers: {
'connection': 'close',
'content-length': buffer.length,
},
}, common.mustCall((res) => {
res.setEncoding('utf8');
res.on('data', common.mustCall((string) => {