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:
parent
a5c27091cc
commit
1f7b6a6cc9
21
test/parallel/test-cluster-kill-infinite-loop.js
Normal file
21
test/parallel/test-cluster-kill-infinite-loop.js
Normal 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) {}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user