2015-11-09 15:08:50 -05:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
2018-03-08 02:24:08 +05:30
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2015-11-09 15:08:50 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const cluster = require('cluster');
|
|
|
|
|
2020-12-10 16:53:44 -05:00
|
|
|
if (cluster.isPrimary) {
|
2015-12-18 19:13:50 +01:00
|
|
|
function forkWorker(action) {
|
|
|
|
const worker = cluster.fork({ action });
|
|
|
|
worker.on('disconnect', common.mustCall(() => {
|
2017-06-15 08:30:20 -07:00
|
|
|
assert.strictEqual(worker.exitedAfterDisconnect, true);
|
2015-12-18 19:13:50 +01:00
|
|
|
}));
|
2015-11-09 15:08:50 -05:00
|
|
|
|
2015-12-18 19:13:50 +01:00
|
|
|
worker.on('exit', common.mustCall(() => {
|
2017-06-15 08:30:20 -07:00
|
|
|
assert.strictEqual(worker.exitedAfterDisconnect, true);
|
2015-12-18 19:13:50 +01:00
|
|
|
}));
|
|
|
|
}
|
2015-11-09 15:08:50 -05:00
|
|
|
|
2015-12-18 19:13:50 +01:00
|
|
|
forkWorker('disconnect');
|
|
|
|
forkWorker('kill');
|
2015-11-09 15:08:50 -05:00
|
|
|
} else {
|
2015-12-18 19:13:50 +01:00
|
|
|
cluster.worker[process.env.action]();
|
2015-11-09 15:08:50 -05:00
|
|
|
}
|