From 992a1e7f5f87606276af8504c2d57cc5a966830a Mon Sep 17 00:00:00 2001 From: Timothy J Fontaine Date: Thu, 15 Jan 2015 23:19:32 +0000 Subject: [PATCH] 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 PR-URL: https://github.com/iojs/io.js/pull/501 Reviewed-By: Ben Noordhuis Reviewed-By: Bert Belder Reviewed-By: Rod Vagg --- test/parallel/test-debug-signal-cluster.js | 60 +++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/test/parallel/test-debug-signal-cluster.js b/test/parallel/test-debug-signal-cluster.js index 05b544f1d8759e..5190bd1cae66d4 100644 --- a/test/parallel/test-debug-signal-cluster.js +++ b/test/parallel/test-debug-signal-cluster.js @@ -14,32 +14,32 @@ var pids = null; child.stderr.on('data', function(data) { 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) - clearTimeout(outputTimerId); + if (line === 'all workers are running') { + child.on('message', function(msg) { + if (msg.type !== 'pids') + return; - if (waitingForDebuggers) { - outputLines = outputLines.concat(lines); - outputTimerId = setTimeout(onNoMoreLines, 800); - } else if (line === 'all workers are running') { - child.on('message', function(msg) { - if (msg.type !== 'pids') - return; + pids = msg.pids; + console.error('got pids %j', pids); - pids = msg.pids; - console.error('got pids %j', pids); + waitingForDebuggers = true; + process._debugProcess(child.pid); + }); - waitingForDebuggers = true; - process._debugProcess(child.pid); - }); + child.send({ + type: 'getpids' + }); + } else if (waitingForDebuggers) { + outputLines.push(line); + } - child.send({ - type: 'getpids' - }); - } + }); + if (outputLines.length >= expectedLines.length) + onNoMoreLines(); }); function onNoMoreLines() { @@ -49,7 +49,7 @@ function onNoMoreLines() { setTimeout(function testTimedOut() { assert(false, 'test timed out.'); -}, 6000); +}, 6000).unref(); process.on('exit', function onExit() { // Kill processes in reverse order to avoid timing problems on Windows where @@ -59,16 +59,16 @@ process.on('exit', function onExit() { }); }); -function assertOutputLines() { - var expectedLines = [ - 'Starting debugger agent.', - 'Debugger listening on port ' + 5858, - 'Starting debugger agent.', - 'Debugger listening on port ' + 5859, - 'Starting debugger agent.', - 'Debugger listening on port ' + 5860, - ]; +var expectedLines = [ + 'Starting debugger agent.', + 'Debugger listening on port ' + 5858, + 'Starting debugger agent.', + 'Debugger listening on port ' + 5859, + 'Starting debugger agent.', + 'Debugger listening on port ' + 5860, +]; +function assertOutputLines() { // Do not assume any particular order of output messages, // since workers can take different amout of time to // start up