Skip to content

Commit a256790

Browse files
mscdexMyles Borins
authored and
Myles Borins
committed
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: #3957 PR-URL: #4444 Reviewed-By: Rich Trott <[email protected]>
1 parent 6809c2b commit a256790

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

test/parallel/parallel.status

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ prefix parallel
77
[true] # This section applies to all platforms
88

99
[$system==win32]
10-
test-cluster-net-send : PASS,FLAKY
1110
test-cluster-shared-leak : PASS,FLAKY
1211
test-debug-no-context : PASS,FLAKY
1312
test-tls-ticket-cluster : PASS,FLAKY

test/parallel/test-cluster-net-send.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,22 @@ if (process.argv[2] !== 'child') {
3131
} else {
3232
console.error('[%d] worker', process.pid);
3333

34+
var socket;
35+
var cbcalls = 0;
36+
function socketConnected() {
37+
if (++cbcalls === 2)
38+
process.send('handle', socket);
39+
}
40+
3441
var server = net.createServer(function(c) {
3542
process.once('message', function(msg) {
3643
assert.equal(msg, 'got');
3744
c.end('hello');
3845
});
46+
socketConnected();
3947
});
4048
server.listen(common.PORT, function() {
41-
var socket = net.connect(common.PORT, '127.0.0.1', function() {
42-
process.send('handle', socket);
43-
});
49+
socket = net.connect(common.PORT, '127.0.0.1', socketConnected);
4450
});
4551

4652
process.on('disconnect', function() {

0 commit comments

Comments
 (0)