|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const cluster = require('cluster'); |
| 5 | + |
| 6 | +if (cluster.isMaster) { |
| 7 | + assert.strictEqual(process.execArgv.length, 0, 'run test with no args'); |
| 8 | + |
| 9 | + function checkExitCode(code, signal) { |
| 10 | + assert.strictEqual(code, 0); |
| 11 | + assert.strictEqual(signal, null); |
| 12 | + } |
| 13 | + |
| 14 | + console.log('forked worker should not have --debug-port'); |
| 15 | + cluster.fork().on('exit', checkExitCode); |
| 16 | + |
| 17 | + cluster.setupMaster({ |
| 18 | + execArgv: ['--debug-port=' + process.debugPort] |
| 19 | + }); |
| 20 | + |
| 21 | + console.log('forked worker should have --debug-port, with offset = 1'); |
| 22 | + cluster.fork({ |
| 23 | + portSet: process.debugPort + 1 |
| 24 | + }).on('exit', checkExitCode); |
| 25 | + |
| 26 | + console.log('forked worker should have --debug-port, with offset = 2'); |
| 27 | + cluster.fork({ |
| 28 | + portSet: process.debugPort + 2 |
| 29 | + }).on('exit', checkExitCode); |
| 30 | +} else { |
| 31 | + const hasDebugArg = process.execArgv.some(function(arg) { |
| 32 | + return /debug/.test(arg); |
| 33 | + }); |
| 34 | + |
| 35 | + assert.strictEqual(hasDebugArg, process.env.portSet !== undefined); |
| 36 | + assert.strictEqual(process.debugPort, +process.env.portSet || 5858); |
| 37 | + process.exit(); |
| 38 | +} |
0 commit comments