• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3common.skipIfInspectorDisabled();
4
5// A test to ensure that cluster properly interoperates with the
6// --inspect-brk option.
7
8const assert = require('assert');
9const cluster = require('cluster');
10const debuggerPort = common.PORT;
11
12if (cluster.isMaster) {
13  function test(execArgv) {
14
15    cluster.setupMaster({
16      execArgv: execArgv,
17      stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'pipe']
18    });
19
20    const worker = cluster.fork();
21
22    // Debugger listening on port [port].
23    worker.process.stderr.once('data', common.mustCall(function() {
24      worker.process.kill('SIGTERM');
25    }));
26
27    worker.process.on('exit', common.mustCall(function(code, signal) {
28      assert.strictEqual(signal, 'SIGTERM');
29    }));
30  }
31
32  test(['--inspect-brk']);
33  test([`--inspect-brk=${debuggerPort}`]);
34} else {
35  // Cluster worker is at a breakpoint, should not reach here.
36  assert.fail('Test failed: cluster worker should be at a breakpoint.');
37}
38