Skip to content

Commit

Permalink
test: fix flaky test-net-connect-econnrefused
Browse files Browse the repository at this point in the history
Test is flaky in CI with `common.PORT` but not flaky if a port is
determined from createServer() first.

PR-URL: #34330
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Trott authored and MylesBorins committed Jul 27, 2020
1 parent fd1ebef commit 8ca8042
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/pummel/test-net-connect-econnrefused.js
Expand Up @@ -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();
Expand Down

0 comments on commit 8ca8042

Please sign in to comment.