From a256790327c0db64c414e400e05f7fa5623f70fc Mon Sep 17 00:00:00 2001 From: Brian White Date: Mon, 28 Dec 2015 01:11:51 -0500 Subject: [PATCH] test: fix flaky cluster-net-send 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: https://github.com/nodejs/node/issues/3957 PR-URL: https://github.com/nodejs/node/pull/4444 Reviewed-By: Rich Trott --- test/parallel/parallel.status | 1 - test/parallel/test-cluster-net-send.js | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 4c41af84937a4e..02302b04acd676 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -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 diff --git a/test/parallel/test-cluster-net-send.js b/test/parallel/test-cluster-net-send.js index 6190fb517e4d1a..fe536b5f2a43c3 100644 --- a/test/parallel/test-cluster-net-send.js +++ b/test/parallel/test-cluster-net-send.js @@ -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() {