}
});
+ process.on('message', function(msg) {
+ if (msg.type === 'getpids') {
+ var pids = [];
+ pids.push(process.pid);
+ for (var key in cluster.workers)
+ pids.push(cluster.workers[key].process.pid);
+ process.send({ type: 'pids', pids: pids });
+ }
+ });
+
for (var i = 0; i < NUMBER_OF_WORKERS; i++) {
cluster.fork();
}
var spawn = require('child_process').spawn;
var args = [ common.fixturesDir + '/clustered-server/app.js' ];
-var child = spawn(process.execPath, args);
+var child = spawn(process.execPath, args, {
+ stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ]
+});
var outputLines = [];
var outputTimerId;
var waitingForDebuggers = false;
+var pids = null;
+
child.stderr.on('data', function(data) {
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
var line = lines[0];
outputLines = outputLines.concat(lines);
outputTimerId = setTimeout(onNoMoreLines, 800);
} else if (line === 'all workers are running') {
- waitingForDebuggers = true;
- process._debugProcess(child.pid);
+ child.on('message', function(msg) {
+ if (msg.type !== 'pids')
+ return;
+
+ pids = msg.pids;
+ console.error('got pids %j', pids);
+
+ waitingForDebuggers = true;
+ process._debugProcess(child.pid);
+ });
+
+ child.send({
+ type: 'getpids'
+ });
}
});
}, 6000);
process.on('exit', function onExit() {
- child.kill();
+ pids.forEach(function(pid) {
+ process.kill(pid);
+ });
});
function assertOutputLines() {