Skip to content

Commit 33e598a

Browse files
committed
test: fix test-child-process-fork-regr-nodejsgh-2847
It's not guaranteed that the first socket that tries to connect is the first that succeeds so the rest of assumptions made in the test are not correct. Fix it by making sure the second socket does not try to connect until the first has succeeded. The IPC channel can already be closed when sending the second socket. It should be allowed. Also, don't start sending messages until the worker is online. Fixes: nodejs/node#8950 PR-URL: nodejs/node#8954 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 4d6297f commit 33e598a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

test/parallel/test-child-process-fork-regr-gh-2847.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,19 @@ var server = net.createServer(function(s) {
4949
server.close();
5050
}));
5151

52-
send();
53-
send(function(err) {
54-
// Ignore errors when sending the second handle because the worker
55-
// may already have exited.
56-
if (err) {
57-
if (err.code !== 'ECONNREFUSED') {
58-
throw err;
59-
}
60-
}
52+
worker.on('online', function() {
53+
send(function(err) {
54+
assert.ifError(err);
55+
send(function(err) {
56+
// Ignore errors when sending the second handle because the worker
57+
// may already have exited.
58+
if (err) {
59+
if ((err.message !== 'channel closed') &&
60+
(err.code !== 'ECONNREFUSED')) {
61+
throw err;
62+
}
63+
}
64+
});
65+
});
6166
});
6267
});

0 commit comments

Comments
 (0)