From 33e598ac5f1c99ee27b894c6a596a51151c6f99c Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 6 Oct 2016 10:40:03 +0200 Subject: [PATCH] test: fix test-child-process-fork-regr-gh-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: https://github.com/nodejs/node/issues/8950 PR-URL: https://github.com/nodejs/node/pull/8954 Reviewed-By: Michael Dawson Reviewed-By: Brian White Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- .../test-child-process-fork-regr-gh-2847.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-child-process-fork-regr-gh-2847.js b/test/parallel/test-child-process-fork-regr-gh-2847.js index e7815db1b471c1..7b4c262fbdcf61 100644 --- a/test/parallel/test-child-process-fork-regr-gh-2847.js +++ b/test/parallel/test-child-process-fork-regr-gh-2847.js @@ -49,14 +49,19 @@ var server = net.createServer(function(s) { server.close(); })); - send(); - send(function(err) { - // Ignore errors when sending the second handle because the worker - // may already have exited. - if (err) { - if (err.code !== 'ECONNREFUSED') { - throw err; - } - } + worker.on('online', function() { + send(function(err) { + assert.ifError(err); + send(function(err) { + // Ignore errors when sending the second handle because the worker + // may already have exited. + if (err) { + if ((err.message !== 'channel closed') && + (err.code !== 'ECONNREFUSED')) { + throw err; + } + } + }); + }); }); });