Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: fix flaky test-cluster-send-handle-twice
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.
  • Loading branch information
Trott committed Mar 30, 2018
commit f97c2b0943809bd7d0c5430cc809d74f4a2134f5
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);
});
}));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very likely tested for very very often already.


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();
});
}