Browse Source

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 <tjfontaine@gmail.com>

PR-URL: https://github.com/iojs/io.js/pull/501
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
v1.8.0-commit
Julien Gilli 10 years ago
committed by Ben Noordhuis
parent
commit
2f33e00d71
  1. 19
      test/sequential/test-debug-port-from-cmdline.js

19
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();

Loading…
Cancel
Save