mirror of https://github.com/lukechilds/node.git
Browse Source
* Adding --inspect-port with debug port, instead of parsing `execArgv` * Export CLI debug options to `process.binding('config').debugOptions` (currently used only in tests) PR-URL: https://github.com/nodejs/node/pull/13619 Refs: https://github.com/nodejs/node/pull/9659 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>v6
cornholio
8 years ago
committed by
Refael Ackermann
6 changed files with 166 additions and 58 deletions
@ -0,0 +1,129 @@ |
|||
'use strict'; |
|||
|
|||
const common = require('../common'); |
|||
|
|||
common.skipIfInspectorDisabled(); |
|||
|
|||
const assert = require('assert'); |
|||
const cluster = require('cluster'); |
|||
|
|||
const debuggerPort = common.PORT; |
|||
const childProcess = require('child_process'); |
|||
|
|||
let offset = 0; |
|||
|
|||
/* |
|||
* This test suite checks that inspector port in cluster is incremented |
|||
* for different execArgv combinations |
|||
*/ |
|||
|
|||
function testRunnerMain() { |
|||
spawnMaster({ |
|||
execArgv: ['--inspect'], |
|||
workers: [{expectedPort: 9230}] |
|||
}); |
|||
|
|||
let port = debuggerPort + offset++ * 10; |
|||
|
|||
spawnMaster({ |
|||
execArgv: [`--inspect=${port}`], |
|||
workers: [ |
|||
{expectedPort: port + 1}, |
|||
{expectedPort: port + 2}, |
|||
{expectedPort: port + 3} |
|||
] |
|||
}); |
|||
|
|||
port = debuggerPort + offset++ * 10; |
|||
|
|||
spawnMaster({ |
|||
execArgv: ['--inspect', `--inspect-port=${port}`], |
|||
workers: [{expectedPort: port + 1}] |
|||
}); |
|||
|
|||
port = debuggerPort + offset++ * 10; |
|||
|
|||
spawnMaster({ |
|||
execArgv: ['--inspect', `--debug-port=${port}`], |
|||
workers: [{expectedPort: port + 1}] |
|||
}); |
|||
|
|||
port = debuggerPort + offset++ * 10; |
|||
|
|||
spawnMaster({ |
|||
execArgv: [`--inspect=0.0.0.0:${port}`], |
|||
workers: [{expectedPort: port + 1, expectedHost: '0.0.0.0'}] |
|||
}); |
|||
|
|||
port = debuggerPort + offset++ * 10; |
|||
|
|||
spawnMaster({ |
|||
execArgv: [`--inspect=127.0.0.1:${port}`], |
|||
workers: [{expectedPort: port + 1, expectedHost: '127.0.0.1'}] |
|||
}); |
|||
|
|||
if (common.hasIPv6) { |
|||
port = debuggerPort + offset++ * 10; |
|||
|
|||
spawnMaster({ |
|||
execArgv: [`--inspect=[::]:${port}`], |
|||
workers: [{expectedPort: port + 1, expectedHost: '::'}] |
|||
}); |
|||
|
|||
port = debuggerPort + offset++ * 10; |
|||
|
|||
spawnMaster({ |
|||
execArgv: [`--inspect=[::1]:${port}`], |
|||
workers: [{expectedPort: port + 1, expectedHost: '::1'}] |
|||
}); |
|||
} |
|||
} |
|||
|
|||
function masterProcessMain() { |
|||
const workers = JSON.parse(process.env.workers); |
|||
|
|||
for (const worker of workers) { |
|||
cluster.fork({ |
|||
expectedPort: worker.expectedPort, |
|||
expectedHost: worker.expectedHost |
|||
}).on('exit', common.mustCall(checkExitCode)); |
|||
} |
|||
} |
|||
|
|||
function workerProcessMain() { |
|||
const {expectedPort, expectedHost} = process.env; |
|||
|
|||
assert.strictEqual(process.debugPort, +expectedPort); |
|||
|
|||
if (expectedHost !== 'undefined') { |
|||
assert.strictEqual( |
|||
process.binding('config').debugOptions.host, |
|||
expectedHost |
|||
); |
|||
} |
|||
|
|||
process.exit(); |
|||
} |
|||
|
|||
function spawnMaster({execArgv, workers}) { |
|||
childProcess.fork(__filename, { |
|||
env: { |
|||
workers: JSON.stringify(workers), |
|||
testProcess: true |
|||
}, |
|||
execArgv |
|||
}).on('exit', common.mustCall(checkExitCode)); |
|||
} |
|||
|
|||
function checkExitCode(code, signal) { |
|||
assert.strictEqual(code, 0); |
|||
assert.strictEqual(signal, null); |
|||
} |
|||
|
|||
if (!process.env.testProcess) { |
|||
testRunnerMain(); |
|||
} else if (cluster.isMaster) { |
|||
masterProcessMain(); |
|||
} else { |
|||
workerProcessMain(); |
|||
} |
@ -1,41 +0,0 @@ |
|||
'use strict'; |
|||
// Flags: --inspect={PORT}
|
|||
const common = require('../common'); |
|||
|
|||
common.skipIfInspectorDisabled(); |
|||
|
|||
const assert = require('assert'); |
|||
const cluster = require('cluster'); |
|||
const debuggerPort = common.PORT; |
|||
|
|||
if (cluster.isMaster) { |
|||
function checkExitCode(code, signal) { |
|||
assert.strictEqual(code, 0); |
|||
assert.strictEqual(signal, null); |
|||
} |
|||
|
|||
function fork(offset, execArgv) { |
|||
if (execArgv) |
|||
cluster.setupMaster({execArgv}); |
|||
|
|||
const check = common.mustCall(checkExitCode); |
|||
cluster.fork({portSet: debuggerPort + offset}).on('exit', check); |
|||
} |
|||
|
|||
assert.strictEqual(process.debugPort, debuggerPort); |
|||
|
|||
fork(1); |
|||
fork(2, ['--inspect']); |
|||
fork(3, [`--inspect=${debuggerPort}`]); |
|||
fork(4, ['--inspect', `--debug-port=${debuggerPort}`]); |
|||
fork(5, [`--inspect-port=${debuggerPort}`]); |
|||
fork(6, ['--inspect', `--inspect-port=${debuggerPort}`]); |
|||
} else { |
|||
const hasDebugArg = process.execArgv.some(function(arg) { |
|||
return /inspect/.test(arg); |
|||
}); |
|||
|
|||
assert.strictEqual(hasDebugArg, true); |
|||
assert.strictEqual(process.debugPort, +process.env.portSet); |
|||
process.exit(); |
|||
} |
Loading…
Reference in new issue