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: nodejs#19700
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott committed Apr 2, 2018
1 parent a9a1f12 commit 4d749e1
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 4d749e1

Please sign in to comment.