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

Commit 7a8ea15

Browse files
author
Julien Gilli
committed
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 <[email protected]>
1 parent 89f3c90 commit 7a8ea15

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

test/simple/test-debug-port-from-cmdline.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ var spawn = require('child_process').spawn;
2525

2626
var debugPort = common.PORT;
2727
var args = ['--debug-port=' + debugPort];
28-
var child = spawn(process.execPath, args);
28+
var childOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] };
29+
var child = spawn(process.execPath, args, childOptions);
30+
31+
child.stdin.end("process.send({ msg: 'childready' });");
2932

3033
child.stderr.on('data', function(data) {
3134
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
3235
lines.forEach(processStderrLine);
3336
});
3437

35-
setTimeout(testTimedOut, 3000);
36-
function testTimedOut() {
37-
assert(false, 'test timed out.');
38-
}
39-
40-
// Give the child process small amout of time to start
41-
setTimeout(function() {
42-
process._debugProcess(child.pid);
43-
}, 100);
38+
child.on('message', function onChildMsg(message) {
39+
if (message.msg === 'childready') {
40+
process._debugProcess(child.pid);
41+
}
42+
});
4443

4544
process.on('exit', function() {
4645
child.kill();

0 commit comments

Comments
 (0)