From 4e9b6a00223b137b0d67e9033a6f311a325df451 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; + } + } + }); + }); }); });