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>
This commit is contained in:
cjihrig 2018-10-03 20:58:40 -04:00
parent a5c27091cc
commit 1f7b6a6cc9
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5

View File

@ -0,0 +1,21 @@
'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) {}
}