From c3ac5e945caa12ad5e43a04917fa273930c10f9c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 12 Jul 2020 17:40:50 -0700 Subject: [PATCH] test: fix flaky test-net-connect-econnrefused Test is flaky in CI with `common.PORT` but not flaky if a port is determined from createServer() first. PR-URL: https://github.com/nodejs/node/pull/34330 Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen --- test/pummel/test-net-connect-econnrefused.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/pummel/test-net-connect-econnrefused.js b/test/pummel/test-net-connect-econnrefused.js index 38a71b6cfd4944..4fd4f8b6943e3c 100644 --- a/test/pummel/test-net-connect-econnrefused.js +++ b/test/pummel/test-net-connect-econnrefused.js @@ -31,12 +31,17 @@ const ATTEMPTS_PER_ROUND = 50; let rounds = 1; let reqs = 0; -pummel(); +let port; +const server = net.createServer().listen(0, common.mustCall(() => { + port = server.address().port; + server.close(common.mustCall(pummel)); +})); function pummel() { let pending; for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) { - net.createConnection(common.PORT).on('error', function(err) { + net.createConnection(port).on('error', function(err) { + console.log('pending', pending, 'rounds', rounds); assert.strictEqual(err.code, 'ECONNREFUSED'); if (--pending > 0) return; if (rounds === ROUNDS) return check();