From 06b5ef3868b0726b12c9ed809149bf824d1c88bd Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 3 Oct 2018 20:58:40 -0400 Subject: [PATCH] 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 Reviewed-By: Sakthipriyan Vairamani --- .../test-cluster-kill-infinite-loop.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/parallel/test-cluster-kill-infinite-loop.js diff --git a/test/parallel/test-cluster-kill-infinite-loop.js b/test/parallel/test-cluster-kill-infinite-loop.js new file mode 100644 index 00000000000000..f53e6e3976ec28 --- /dev/null +++ b/test/parallel/test-cluster-kill-infinite-loop.js @@ -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) {} +}