1 var common = require('../common');
2 var assert = require('assert');
3 var spawn = require('child_process').spawn;
5 var port = common.PORT + 42;
6 var args = ['--debug-port=' + port,
7 common.fixturesDir + '/clustered-server/app.js'];
8 var options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] };
9 var child = spawn(process.execPath, args, options);
13 var waitingForDebuggers = false;
17 child.stderr.on('data', function(data) {
18 var lines = data.toString().replace(/\r/g, '').trim().split('\n');
20 lines.forEach(function(line) {
21 console.log('> ' + line);
23 if (line === 'all workers are running') {
24 child.on('message', function(msg) {
25 if (msg.type !== 'pids')
29 console.error('got pids %j', pids);
31 waitingForDebuggers = true;
32 process._debugProcess(child.pid);
38 } else if (waitingForDebuggers) {
39 outputLines.push(line);
43 if (outputLines.length >= expectedLines.length)
47 function onNoMoreLines() {
52 setTimeout(function testTimedOut() {
53 assert(false, 'test timed out.');
54 }, common.platformTimeout(3000)).unref();
56 process.on('exit', function onExit() {
57 // Kill processes in reverse order to avoid timing problems on Windows where
58 // the parent process is killed before the children.
59 pids.reverse().forEach(function(pid) {
65 'Starting debugger agent.',
66 'Debugger listening on port ' + (port + 0),
67 'Starting debugger agent.',
68 'Debugger listening on port ' + (port + 1),
69 'Starting debugger agent.',
70 'Debugger listening on port ' + (port + 2),
73 function assertOutputLines() {
74 // Do not assume any particular order of output messages,
75 // since workers can take different amout of time to
80 assert.equal(outputLines.length, expectedLines.length);
81 for (var i = 0; i < expectedLines.length; i++)
82 assert.equal(outputLines[i], expectedLines[i]);