Skip to content

Commit

Permalink
test: fix flaky test-cluster-send-handle-twice
Browse files Browse the repository at this point in the history
Use `common.mustCall()` to make sure connection callback runs exactly
once.

Use `connect` event instead of `setTimeout` to avoid test failing if
timer runs before client is connected.

Remove `cluster.worker.disconnect()` after `assert.fail()`. It is
unreachable code that is unnecessary.

PR-URL: #19700
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and BethGriggs committed Dec 4, 2018
1 parent 33b7c50 commit a7b3274
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions test/parallel/test-cluster-send-handle-twice.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,20 @@ if (cluster.isMaster) {
}));
}
} else {
const server = net.createServer(function(socket) {
const server = net.createServer(common.mustCall((socket) => {
process.send('send-handle-1', socket);
process.send('send-handle-2', socket);
});
}));

server.listen(0, function() {
const client = net.connect({
host: 'localhost',
port: server.address().port
});
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
setTimeout(function() { client.end(); }, 50);
client.on('connect', () => { client.end(); });
}).on('error', function(e) {
console.error(e);
assert.fail('server.listen failed');
cluster.worker.disconnect();
});
}

0 comments on commit a7b3274

Please sign in to comment.