Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

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.

Reviewed-By: Timothy J Fontaine <[email protected]>
  • Loading branch information
Julien Gilli committed Jan 16, 2015
1 parent 89f3c90 commit 7a8ea15
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions test/simple/test-debug-port-from-cmdline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7a8ea15

Please sign in to comment.