Skip to content

Commit 2f33e00

Browse files
Julien Gillibnoordhuis
Julien Gilli
authored andcommitted
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: nodejs/node-v0.x-archive#9049 Reviewed-By: Timothy J Fontaine <[email protected]> PR-URL: #501 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Bert Belder <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent b7365c1 commit 2f33e00

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ var spawn = require('child_process').spawn;
44

55
var debugPort = common.PORT;
66
var args = ['--debug-port=' + debugPort];
7-
var child = spawn(process.execPath, args);
7+
var childOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] };
8+
var child = spawn(process.execPath, args, childOptions);
9+
10+
child.stdin.end("process.send({ msg: 'childready' });");
811

912
child.stderr.on('data', function(data) {
1013
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
1114
lines.forEach(processStderrLine);
1215
});
1316

14-
setTimeout(testTimedOut, 3000);
15-
function testTimedOut() {
16-
assert(false, 'test timed out.');
17-
}
18-
19-
// Give the child process small amout of time to start
20-
setTimeout(function() {
21-
process._debugProcess(child.pid);
22-
}, 100);
17+
child.on('message', function onChildMsg(message) {
18+
if (message.msg === 'childready') {
19+
process._debugProcess(child.pid);
20+
}
21+
});
2322

2423
process.on('exit', function() {
2524
child.kill();

0 commit comments

Comments
 (0)