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

Commit 58fcc65

Browse files
tjfontaineJulien Gilli
authored and
Julien Gilli
committed
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. Signed-off-by: Julien Gilli <julien.gilli@joyent.com>
1 parent e9df9a0 commit 58fcc65

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

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

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

3636
child.stderr.on('data', function(data) {
3737
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
38-
var line = lines[0];
3938

40-
lines.forEach(function(ln) { console.log('> ' + ln) } );
39+
lines.forEach(function(line) {
40+
console.log('> ' + line);
4141

42-
if (outputTimerId !== undefined)
43-
clearTimeout(outputTimerId);
42+
if (line === 'all workers are running') {
43+
child.on('message', function(msg) {
44+
if (msg.type !== 'pids')
45+
return;
4446

45-
if (waitingForDebuggers) {
46-
outputLines = outputLines.concat(lines);
47-
outputTimerId = setTimeout(onNoMoreLines, 800);
48-
} else if (line === 'all workers are running') {
49-
child.on('message', function(msg) {
50-
if (msg.type !== 'pids')
51-
return;
47+
pids = msg.pids;
48+
console.error('got pids %j', pids);
5249

53-
pids = msg.pids;
54-
console.error('got pids %j', pids);
50+
waitingForDebuggers = true;
51+
process._debugProcess(child.pid);
52+
});
5553

56-
waitingForDebuggers = true;
57-
process._debugProcess(child.pid);
58-
});
54+
child.send({
55+
type: 'getpids'
56+
});
57+
} else if (waitingForDebuggers) {
58+
outputLines.push(line);
59+
}
5960

60-
child.send({
61-
type: 'getpids'
62-
});
63-
}
61+
});
62+
if (outputLines.length >= expectedLines.length)
63+
onNoMoreLines();
6464
});
6565

6666
function onNoMoreLines() {
@@ -70,24 +70,24 @@ function onNoMoreLines() {
7070

7171
setTimeout(function testTimedOut() {
7272
assert(false, 'test timed out.');
73-
}, 6000);
73+
}, 6000).unref();
7474

7575
process.on('exit', function onExit() {
7676
pids.forEach(function(pid) {
7777
process.kill(pid);
7878
});
7979
});
8080

81-
function assertOutputLines() {
82-
var expectedLines = [
83-
'Starting debugger agent.',
84-
'Debugger listening on port ' + 5858,
85-
'Starting debugger agent.',
86-
'Debugger listening on port ' + 5859,
87-
'Starting debugger agent.',
88-
'Debugger listening on port ' + 5860,
89-
];
81+
var expectedLines = [
82+
'Starting debugger agent.',
83+
'Debugger listening on port ' + 5858,
84+
'Starting debugger agent.',
85+
'Debugger listening on port ' + 5859,
86+
'Starting debugger agent.',
87+
'Debugger listening on port ' + 5860,
88+
];
9089

90+
function assertOutputLines() {
9191
// Do not assume any particular order of output messages,
9292
// since workers can take different amout of time to
9393
// start up

0 commit comments

Comments
 (0)