node/test/parallel/test-cluster-kill-infinite-loop.js
cjihrig 1f7b6a6cc9
test: terminate cluster worker in infinite loop
Verify that worker.process.kill() can terminate a cluster worker
stuck in an infinite loop.

PR-URL: https://github.com/nodejs/node/pull/23165
Fixes: https://github.com/nodejs/node/issues/22703
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2018-10-04 09:02:47 -04:00

22 lines
574 B
JavaScript

'use strict';
const common = require('../common');
const cluster = require('cluster');
const assert = require('assert');
if (cluster.isMaster) {
const worker = cluster.fork();
worker.on('online', common.mustCall(() => {
// Use worker.process.kill() instead of worker.kill() because the latter
// waits for a graceful disconnect, which will never happen.
worker.process.kill();
}));
worker.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGTERM');
}));
} else {
while (true) {}
}