summaryrefslogtreecommitdiff
path: root/test/parallel/test-cluster-setup-master-emit.js
blob: ad15c084c5924d3914b1f2e2686784e657c2c6ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
require('../common');
var assert = require('assert');
var cluster = require('cluster');

assert(cluster.isMaster);

var assertsRun = 0;

function emitAndCatch(next) {
  cluster.once('setup', function(settings) {
    assert.strictEqual(settings.exec, 'new-exec');
    console.log('ok "setup" emitted with options set');
    assertsRun += 1;
    setImmediate(next);
  });
  cluster.setupMaster({ exec: 'new-exec' });
}

function emitAndCatch2(next) {
  cluster.once('setup', function(settings) {
    assert('exec' in settings);
    console.log('ok "setup" emitted without options set');
    assertsRun += 1;
    setImmediate(next);
  });
  cluster.setupMaster();
}

process.on('exit', function() {
  assert.strictEqual(assertsRun, 2);
  console.log('ok correct number of assertions');
});

emitAndCatch(function() {
  emitAndCatch2(function() {
    console.log('ok emitted and caught');
  });
});