From 2f33e00d716d692e84b02768430664fd92298c98 Mon Sep 17 00:00:00 2001 From: Julien Gilli Date: Fri, 16 Jan 2015 14:29:01 -0800 Subject: [PATCH] test: fix test-debug-port-from-cmdline.js Make this test less prone to race conditions by using synchronous interprocess communication instead of a timer to determine when the child process is ready to receive messages from its parent. Also, remove a superfluous timer since the tests suite already makes tests time out after a while. Original-PR-URL: https://github.com/joyent/node/pull/9049 Reviewed-By: Timothy J Fontaine PR-URL: https://github.com/iojs/io.js/pull/501 Reviewed-By: Ben Noordhuis Reviewed-By: Bert Belder Reviewed-By: Rod Vagg --- .../test-debug-port-from-cmdline.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/sequential/test-debug-port-from-cmdline.js b/test/sequential/test-debug-port-from-cmdline.js index 3a7f081ec7e298..4ed2e84918c8f0 100644 --- a/test/sequential/test-debug-port-from-cmdline.js +++ b/test/sequential/test-debug-port-from-cmdline.js @@ -4,22 +4,21 @@ var spawn = require('child_process').spawn; var debugPort = common.PORT; var args = ['--debug-port=' + debugPort]; -var child = spawn(process.execPath, args); +var childOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }; +var child = spawn(process.execPath, args, childOptions); + +child.stdin.end("process.send({ msg: 'childready' });"); child.stderr.on('data', function(data) { var lines = data.toString().replace(/\r/g, '').trim().split('\n'); lines.forEach(processStderrLine); }); -setTimeout(testTimedOut, 3000); -function testTimedOut() { - assert(false, 'test timed out.'); -} - -// Give the child process small amout of time to start -setTimeout(function() { - process._debugProcess(child.pid); -}, 100); +child.on('message', function onChildMsg(message) { + if (message.msg === 'childready') { + process._debugProcess(child.pid); + } +}); process.on('exit', function() { child.kill();