diff options
author | Julien Gilli <julien.gilli@joyent.com> | 2015-01-16 14:29:01 -0800 |
---|---|---|
committer | Julien Gilli <julien.gilli@joyent.com> | 2015-01-16 14:59:29 -0800 |
commit | 7a8ea15d6fbbf14ee1aef50714ae254f2130b9b5 (patch) | |
tree | 5abb5cdbdd25b48c48ae2e31dc247b056cee6153 | |
parent | 89f3c9037faf19eb32c464b2e02a0a9191156c36 (diff) | |
download | node-new-7a8ea15d6fbbf14ee1aef50714ae254f2130b9b5.tar.gz |
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.
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
-rw-r--r-- | test/simple/test-debug-port-from-cmdline.js | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/test/simple/test-debug-port-from-cmdline.js b/test/simple/test-debug-port-from-cmdline.js index db0f1b382e..54ac2d5d6d 100644 --- a/test/simple/test-debug-port-from-cmdline.js +++ b/test/simple/test-debug-port-from-cmdline.js @@ -25,22 +25,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(); |