summaryrefslogtreecommitdiff
path: root/test/parallel/test-cluster-kill-disconnect.js
blob: f5407612a83b5f281680c2f29e99467c86956ab0 (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
'use strict';
const common = require('../common');

// Check that cluster works perfectly for both `kill` and `disconnect` cases.
// Also take into account that the `disconnect` event may be received after the
// `exit` event.
// https://github.com/nodejs/node/issues/3238

const assert = require('assert');
const cluster = require('cluster');

if (cluster.isMaster) {
  function forkWorker(action) {
    const worker = cluster.fork({ action });
    worker.on('disconnect', common.mustCall(() => {
      assert.strictEqual(worker.exitedAfterDisconnect, true);
    }));

    worker.on('exit', common.mustCall(() => {
      assert.strictEqual(worker.exitedAfterDisconnect, true);
    }));
  }

  forkWorker('disconnect');
  forkWorker('kill');
} else {
  cluster.worker[process.env.action]();
}