Skip to content

Commit c3ac5e9

Browse files
Trottaddaleax
authored andcommitted
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: #34330 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent bd3cef7 commit c3ac5e9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/pummel/test-net-connect-econnrefused.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ const ATTEMPTS_PER_ROUND = 50;
3131
let rounds = 1;
3232
let reqs = 0;
3333

34-
pummel();
34+
let port;
35+
const server = net.createServer().listen(0, common.mustCall(() => {
36+
port = server.address().port;
37+
server.close(common.mustCall(pummel));
38+
}));
3539

3640
function pummel() {
3741
let pending;
3842
for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) {
39-
net.createConnection(common.PORT).on('error', function(err) {
43+
net.createConnection(port).on('error', function(err) {
44+
console.log('pending', pending, 'rounds', rounds);
4045
assert.strictEqual(err.code, 'ECONNREFUSED');
4146
if (--pending > 0) return;
4247
if (rounds === ROUNDS) return check();

0 commit comments

Comments
 (0)