mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
8 years ago
|
// Flags: --inspect=0
|
||
|
'use strict';
|
||
|
const common = require('../common');
|
||
8 years ago
|
|
||
8 years ago
|
common.skipIfInspectorDisabled();
|
||
8 years ago
|
|
||
8 years ago
|
// Assert that even when started with `--inspect=0` workers are assigned
|
||
|
// consecutive (i.e. deterministically predictable) debug ports
|
||
|
|
||
8 years ago
|
const assert = require('assert');
|
||
|
const cluster = require('cluster');
|
||
|
|
||
8 years ago
|
function serialFork() {
|
||
|
return new Promise((res) => {
|
||
|
const worker = cluster.fork();
|
||
|
worker.on('exit', common.mustCall((code, signal) => {
|
||
|
// code 0 is normal
|
||
|
// code 12 can happen if inspector could not bind because of a port clash
|
||
|
if (code !== 0 && code !== 12)
|
||
|
assert.fail(`code: ${code}, signal: ${signal}`);
|
||
|
const port = worker.process.spawnargs
|
||
|
.map((a) => (/=(?:.*:)?(\d{2,5})$/.exec(a) || [])[1])
|
||
|
.filter((p) => p)
|
||
|
.pop();
|
||
|
res(Number(port));
|
||
8 years ago
|
}));
|
||
|
});
|
||
8 years ago
|
}
|
||
|
|
||
|
if (cluster.isMaster) {
|
||
|
Promise.all([serialFork(), serialFork(), serialFork()])
|
||
|
.then(common.mustCall((ports) => {
|
||
|
ports.push(process.debugPort);
|
||
|
ports.sort();
|
||
|
// 4 = [master, worker1, worker2, worker3].length()
|
||
|
assert.strictEqual(ports.length, 4);
|
||
|
assert(ports.every((port) => port > 0));
|
||
|
assert(ports.every((port) => port < 65536));
|
||
|
// Ports should be consecutive.
|
||
|
assert.strictEqual(ports[0] + 1, ports[1]);
|
||
|
assert.strictEqual(ports[1] + 1, ports[2]);
|
||
|
assert.strictEqual(ports[2] + 1, ports[3]);
|
||
|
}))
|
||
|
.catch(
|
||
|
(err) => {
|
||
|
console.error(err);
|
||
|
process.exit(1);
|
||
|
});
|
||
8 years ago
|
} else {
|
||
8 years ago
|
process.exit(0);
|
||
8 years ago
|
}
|