Skip to content

Commit

Permalink
test: fix flaky cluster-net-send
Browse files Browse the repository at this point in the history
Before this commit, it was possible on Windows for the server's
'connection' handler to be called *after* the client socket's
'connect' handler. This caused the 'message' event to be missed
and the test would never end (timing out in CI). This problem
was more easily reproducible on a low resource (slow CPU)
Windows (2012r2) installation.

This commit waits until both handlers have been called before
sending the handle to the master process.

Fixes: #3957
PR-URL: #4444
  • Loading branch information
mscdex committed Dec 29, 2015
1 parent 30c0062 commit 0fb7ef2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ prefix parallel
[true] # This section applies to all platforms

[$system==win32]
test-cluster-net-send : PASS,FLAKY
test-cluster-shared-leak : PASS,FLAKY
test-debug-no-context : PASS,FLAKY
test-tls-ticket-cluster : PASS,FLAKY
Expand Down
12 changes: 9 additions & 3 deletions test/parallel/test-cluster-net-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@ if (process.argv[2] !== 'child') {
} else {
console.error('[%d] worker', process.pid);

var socket;
var cbcalls = 0;
function socketConnected() {
if (++cbcalls === 2)
process.send('handle', socket);
}

var server = net.createServer(function(c) {
process.once('message', function(msg) {
assert.equal(msg, 'got');
c.end('hello');
});
socketConnected();
});
server.listen(common.PORT, function() {
var socket = net.connect(common.PORT, '127.0.0.1', function() {
process.send('handle', socket);
});
socket = net.connect(common.PORT, '127.0.0.1', socketConnected);
});

process.on('disconnect', function() {
Expand Down

0 comments on commit 0fb7ef2

Please sign in to comment.