0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-cluster-debug-port.js
cjihrig c4f80c1f34 cluster: rewrite debug ports consistently
When debug flags are passed to clustered applications, the debug
port is rewritten for each worker process to avoid collisions.
Prior to this commit, each debug flag would get a unique value.
This commit reworks the logic to assign the same port value to
all debug flags for a single worker.

PR-URL: https://github.com/nodejs/node/pull/7050
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-05-31 09:21:00 -04:00

43 lines
1.1 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const cluster = require('cluster');
if (cluster.isMaster) {
function checkExitCode(code, signal) {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
}
console.log('forked worker should not have --debug-port');
cluster.fork().on('exit', checkExitCode);
cluster.setupMaster({
execArgv: ['--debug-port=' + process.debugPort]
});
console.log('forked worker should have --debug-port, with offset = 1');
cluster.fork({
portSet: process.debugPort + 1
}).on('exit', checkExitCode);
cluster.setupMaster({
execArgv: [`--debug-port=${process.debugPort}`,
`--debug=${process.debugPort}`]
});
console.log('forked worker should have --debug-port, with offset = 2');
cluster.fork({
portSet: process.debugPort + 2
}).on('exit', checkExitCode);
} else {
const hasDebugArg = process.execArgv.some(function(arg) {
return /debug/.test(arg);
});
assert.strictEqual(hasDebugArg, process.env.portSet !== undefined);
assert.strictEqual(process.debugPort, +process.env.portSet || 5858);
process.exit();
}