Skip to content

Commit 992a1e7

Browse files
tjfontainebnoordhuis
authored andcommitted
test: debug-signal-cluster should not be racey
unref one superfluous timer (as the test suite already has a global timeout), and improve the state machine to iterate the messages more reliably. Ultimately make the test complete more quickly. Original-PR-URL: [unknown] Signed-off-by: Julien Gilli <[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 cdf0df1 commit 992a1e7

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

test/parallel/test-debug-signal-cluster.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ var pids = null;
1414

1515
child.stderr.on('data', function(data) {
1616
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
17-
var line = lines[0];
1817

19-
lines.forEach(function(ln) { console.log('> ' + ln) } );
18+
lines.forEach(function(line) {
19+
console.log('> ' + line);
2020

21-
if (outputTimerId !== undefined)
22-
clearTimeout(outputTimerId);
21+
if (line === 'all workers are running') {
22+
child.on('message', function(msg) {
23+
if (msg.type !== 'pids')
24+
return;
2325

24-
if (waitingForDebuggers) {
25-
outputLines = outputLines.concat(lines);
26-
outputTimerId = setTimeout(onNoMoreLines, 800);
27-
} else if (line === 'all workers are running') {
28-
child.on('message', function(msg) {
29-
if (msg.type !== 'pids')
30-
return;
26+
pids = msg.pids;
27+
console.error('got pids %j', pids);
3128

32-
pids = msg.pids;
33-
console.error('got pids %j', pids);
29+
waitingForDebuggers = true;
30+
process._debugProcess(child.pid);
31+
});
3432

35-
waitingForDebuggers = true;
36-
process._debugProcess(child.pid);
37-
});
33+
child.send({
34+
type: 'getpids'
35+
});
36+
} else if (waitingForDebuggers) {
37+
outputLines.push(line);
38+
}
3839

39-
child.send({
40-
type: 'getpids'
41-
});
42-
}
40+
});
41+
if (outputLines.length >= expectedLines.length)
42+
onNoMoreLines();
4343
});
4444

4545
function onNoMoreLines() {
@@ -49,7 +49,7 @@ function onNoMoreLines() {
4949

5050
setTimeout(function testTimedOut() {
5151
assert(false, 'test timed out.');
52-
}, 6000);
52+
}, 6000).unref();
5353

5454
process.on('exit', function onExit() {
5555
// Kill processes in reverse order to avoid timing problems on Windows where
@@ -59,16 +59,16 @@ process.on('exit', function onExit() {
5959
});
6060
});
6161

62-
function assertOutputLines() {
63-
var expectedLines = [
64-
'Starting debugger agent.',
65-
'Debugger listening on port ' + 5858,
66-
'Starting debugger agent.',
67-
'Debugger listening on port ' + 5859,
68-
'Starting debugger agent.',
69-
'Debugger listening on port ' + 5860,
70-
];
62+
var expectedLines = [
63+
'Starting debugger agent.',
64+
'Debugger listening on port ' + 5858,
65+
'Starting debugger agent.',
66+
'Debugger listening on port ' + 5859,
67+
'Starting debugger agent.',
68+
'Debugger listening on port ' + 5860,
69+
];
7170

71+
function assertOutputLines() {
7272
// Do not assume any particular order of output messages,
7373
// since workers can take different amout of time to
7474
// start up

0 commit comments

Comments
 (0)