2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const cluster = require('cluster');
|
2013-12-02 19:00:39 -08:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const SENTINEL = 42;
|
2013-12-02 19:00:39 -08:00
|
|
|
|
2018-12-03 17:15:45 +01:00
|
|
|
// Workers forcibly exit when control channel is disconnected, if
|
2015-11-10 13:14:34 -06:00
|
|
|
// their .exitedAfterDisconnect flag isn't set
|
2013-12-02 19:00:39 -08:00
|
|
|
//
|
|
|
|
// test this by:
|
|
|
|
//
|
|
|
|
// 1 setup worker to wait a short time after disconnect, and exit
|
|
|
|
// with a sentinel value
|
|
|
|
// 2 disconnect worker with cluster's disconnect, confirm sentinel
|
|
|
|
// 3 disconnect worker with child_process's disconnect, confirm
|
|
|
|
// no sentinel value
|
|
|
|
if (cluster.isWorker) {
|
2018-10-12 10:43:47 -07:00
|
|
|
process.on('disconnect', (msg) => {
|
|
|
|
setTimeout(() => process.exit(SENTINEL), 10);
|
2013-12-02 19:00:39 -08:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkUnforced();
|
|
|
|
checkForced();
|
|
|
|
|
|
|
|
function checkUnforced() {
|
2018-10-12 10:43:47 -07:00
|
|
|
const worker = cluster.fork();
|
|
|
|
worker
|
|
|
|
.on('online', common.mustCall(() => worker.disconnect()))
|
|
|
|
.on('exit', common.mustCall((status) => {
|
2016-07-29 21:41:10 -07:00
|
|
|
assert.strictEqual(status, SENTINEL);
|
|
|
|
}));
|
2013-12-02 19:00:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkForced() {
|
2018-10-12 10:43:47 -07:00
|
|
|
const worker = cluster.fork();
|
|
|
|
worker
|
|
|
|
.on('online', common.mustCall(() => worker.process.disconnect()))
|
|
|
|
.on('exit', common.mustCall((status) => assert.strictEqual(status, 0)));
|
2013-12-02 19:00:39 -08:00
|
|
|
}
|