lib: make --debug-port work with cluster

Make the cluster module intercept the `--debug-port=<port>` command line
switch and replace it with the debug port of the child process.

A happy coincidence of this change is that it finally makes it possible
to run the sequential/test-debug-signal-cluster in parallel, it now no
longer needs the default port numbers.

PR-URL: https://github.com/iojs/io.js/pull/306
Reviewed-By: Miroslav Bajtoš <miroslav@strongloop.com>
This commit is contained in:
Ben Noordhuis 2015-01-12 14:07:55 +01:00
parent 5ec5fd83d4
commit 11c1bae734
2 changed files with 10 additions and 8 deletions

View File

@ -308,7 +308,7 @@ function masterInit() {
workerEnv.NODE_UNIQUE_ID = '' + id; workerEnv.NODE_UNIQUE_ID = '' + id;
for (var i = 0; i < execArgv.length; i++) { for (var i = 0; i < execArgv.length; i++) {
var match = execArgv[i].match(/^(--debug|--debug-brk)(=\d+)?$/); var match = execArgv[i].match(/^(--debug|--debug-(brk|port))(=\d+)?$/);
if (match) { if (match) {
execArgv[i] = match[1] + '=' + debugPort; execArgv[i] = match[1] + '=' + debugPort;

View File

@ -23,10 +23,12 @@ var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var args = [ common.fixturesDir + '/clustered-server/app.js' ]; var port = common.PORT + 42;
var child = spawn(process.execPath, args, { var args = ['--debug-port=' + port,
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ] common.fixturesDir + '/clustered-server/app.js'];
}); var options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] };
var child = spawn(process.execPath, args, options);
var outputLines = []; var outputLines = [];
var outputTimerId; var outputTimerId;
var waitingForDebuggers = false; var waitingForDebuggers = false;
@ -83,11 +85,11 @@ process.on('exit', function onExit() {
function assertOutputLines() { function assertOutputLines() {
var expectedLines = [ var expectedLines = [
'Starting debugger agent.', 'Starting debugger agent.',
'Debugger listening on port ' + 5858, 'Debugger listening on port ' + (port + 0),
'Starting debugger agent.', 'Starting debugger agent.',
'Debugger listening on port ' + 5859, 'Debugger listening on port ' + (port + 1),
'Starting debugger agent.', 'Starting debugger agent.',
'Debugger listening on port ' + 5860, 'Debugger listening on port ' + (port + 2),
]; ];
// Do not assume any particular order of output messages, // Do not assume any particular order of output messages,