mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user