From 11c1bae734dae3a017f2c4f3f71b5e679a9ddfa6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 12 Jan 2015 14:07:55 +0100 Subject: [PATCH] lib: make --debug-port work with cluster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the cluster module intercept the `--debug-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š --- lib/cluster.js | 2 +- test/sequential/test-debug-signal-cluster.js | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/cluster.js b/lib/cluster.js index ba13daadbc7cbf..97a4eb456ba366 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -308,7 +308,7 @@ function masterInit() { workerEnv.NODE_UNIQUE_ID = '' + id; 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) { execArgv[i] = match[1] + '=' + debugPort; diff --git a/test/sequential/test-debug-signal-cluster.js b/test/sequential/test-debug-signal-cluster.js index cd57e548a93601..df96395dc42d00 100644 --- a/test/sequential/test-debug-signal-cluster.js +++ b/test/sequential/test-debug-signal-cluster.js @@ -23,10 +23,12 @@ var common = require('../common'); var assert = require('assert'); var spawn = require('child_process').spawn; -var args = [ common.fixturesDir + '/clustered-server/app.js' ]; -var child = spawn(process.execPath, args, { - stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ] -}); +var port = common.PORT + 42; +var args = ['--debug-port=' + port, + common.fixturesDir + '/clustered-server/app.js']; +var options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] }; +var child = spawn(process.execPath, args, options); + var outputLines = []; var outputTimerId; var waitingForDebuggers = false; @@ -83,11 +85,11 @@ process.on('exit', function onExit() { function assertOutputLines() { var expectedLines = [ 'Starting debugger agent.', - 'Debugger listening on port ' + 5858, + 'Debugger listening on port ' + (port + 0), 'Starting debugger agent.', - 'Debugger listening on port ' + 5859, + 'Debugger listening on port ' + (port + 1), 'Starting debugger agent.', - 'Debugger listening on port ' + 5860, + 'Debugger listening on port ' + (port + 2), ]; // Do not assume any particular order of output messages,