Skip to content

Commit

Permalink
test: fix test-debug-port-from-cmdline.js
Browse files Browse the repository at this point in the history
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: nodejs/node-v0.x-archive#9049
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>

PR-URL: #501
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
  • Loading branch information
Julien Gilli authored and bnoordhuis committed Jan 19, 2015
1 parent b7365c1 commit 2f33e00
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions test/sequential/test-debug-port-from-cmdline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2f33e00

Please sign in to comment.