node/test/parallel/test-cluster-kill-disconnect.js
Michael Dawson 15164cebce lib,src: update cluster to use Parent
Doc deprecate isMaster and setupMaster in favor
of isPrimary and setupPrimary.

Signed-off-by: Michael Dawson <mdawson@devrus.com>

PR-URL: https://github.com/nodejs/node/pull/36478
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
2021-01-05 15:41:45 -05:00

29 lines
794 B
JavaScript

'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.isPrimary) {
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]();
}