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 <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
Trott authored and addaleax committed Sep 22, 2020
1 parent bd3cef7 commit c3ac5e9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/pummel/test-net-connect-econnrefused.js
Original file line number Diff line number Diff line change
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 c3ac5e9

Please sign in to comment.