Browse Source

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>
v0.11.15-release
Timothy J Fontaine 10 years ago
committed by Julien Gilli
parent
commit
58fcc65985
  1. 60
      test/simple/test-debug-signal-cluster.js

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

@ -35,32 +35,32 @@ var pids = null;
child.stderr.on('data', function(data) { child.stderr.on('data', function(data) {
var lines = data.toString().replace(/\r/g, '').trim().split('\n'); var lines = data.toString().replace(/\r/g, '').trim().split('\n');
var line = lines[0];
lines.forEach(function(ln) { console.log('> ' + ln) } ); lines.forEach(function(line) {
console.log('> ' + line);
if (outputTimerId !== undefined) if (line === 'all workers are running') {
clearTimeout(outputTimerId); child.on('message', function(msg) {
if (msg.type !== 'pids')
return;
if (waitingForDebuggers) { pids = msg.pids;
outputLines = outputLines.concat(lines); console.error('got pids %j', pids);
outputTimerId = setTimeout(onNoMoreLines, 800);
} else if (line === 'all workers are running') {
child.on('message', function(msg) {
if (msg.type !== 'pids')
return;
pids = msg.pids; waitingForDebuggers = true;
console.error('got pids %j', pids); process._debugProcess(child.pid);
});
waitingForDebuggers = true; child.send({
process._debugProcess(child.pid); type: 'getpids'
}); });
} else if (waitingForDebuggers) {
outputLines.push(line);
}
child.send({ });
type: 'getpids' if (outputLines.length >= expectedLines.length)
}); onNoMoreLines();
}
}); });
function onNoMoreLines() { function onNoMoreLines() {
@ -70,7 +70,7 @@ function onNoMoreLines() {
setTimeout(function testTimedOut() { setTimeout(function testTimedOut() {
assert(false, 'test timed out.'); assert(false, 'test timed out.');
}, 6000); }, 6000).unref();
process.on('exit', function onExit() { process.on('exit', function onExit() {
pids.forEach(function(pid) { pids.forEach(function(pid) {
@ -78,16 +78,16 @@ process.on('exit', function onExit() {
}); });
}); });
function assertOutputLines() { var expectedLines = [
var expectedLines = [ 'Starting debugger agent.',
'Starting debugger agent.', 'Debugger listening on port ' + 5858,
'Debugger listening on port ' + 5858, 'Starting debugger agent.',
'Starting debugger agent.', 'Debugger listening on port ' + 5859,
'Debugger listening on port ' + 5859, 'Starting debugger agent.',
'Starting debugger agent.', 'Debugger listening on port ' + 5860,
'Debugger listening on port ' + 5860, ];
];
function assertOutputLines() {
// Do not assume any particular order of output messages, // Do not assume any particular order of output messages,
// since workers can take different amout of time to // since workers can take different amout of time to
// start up // start up

Loading…
Cancel
Save