Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBar Admoni <bar6020677@gmail.com>2022-02-05 02:15:24 +0300
committerGitHub <noreply@github.com>2022-02-05 02:15:24 +0300
commit38007df999430798908f442ea187cd83978515e5 (patch)
tree400445d4a0c085320bb4f71cb54f81e196202242 /test
parent6c0eb942b3d1851773fd31adf7b8cd2e6ccb405a (diff)
cluster: make `kill` to be just `process.kill`
Make `Worker.prototype.kill` to be just `process.kill` without preforming graceful disconnect beforehand. Refs: https://github.com/nodejs/node/issues/33715 PR-URL: https://github.com/nodejs/node/pull/34312 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-cluster-worker-kill-signal.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/parallel/test-cluster-worker-kill-signal.js b/test/parallel/test-cluster-worker-kill-signal.js
new file mode 100644
index 00000000000..2f1a8ae991d
--- /dev/null
+++ b/test/parallel/test-cluster-worker-kill-signal.js
@@ -0,0 +1,49 @@
+'use strict';
+// test-cluster-worker-kill-signal.js
+// verifies that when we're killing a worker using Worker.prototype.kill
+// and the worker's process was killed with the given signal (SIGKILL)
+
+
+const common = require('../common');
+const assert = require('assert');
+const cluster = require('cluster');
+
+if (cluster.isWorker) {
+ // Make the worker run something
+ const http = require('http');
+ const server = http.Server(() => { });
+
+ server.once('listening', common.mustCall(() => { }));
+ server.listen(0, '127.0.0.1');
+
+} else if (cluster.isMaster) {
+ const KILL_SIGNAL = 'SIGKILL';
+
+ // Start worker
+ const worker = cluster.fork();
+
+ // When the worker is up and running, kill it
+ worker.once('listening', common.mustCall(() => {
+ worker.kill(KILL_SIGNAL);
+ }));
+
+ // Check worker events and properties
+ worker.on('disconnect', common.mustCall(() => {
+ assert.strictEqual(worker.exitedAfterDisconnect, false);
+ assert.strictEqual(worker.state, 'disconnected');
+ }, 1));
+
+ // Check that the worker died
+ worker.once('exit', common.mustCall((exitCode, signalCode) => {
+ const isWorkerProcessStillAlive = common.isAlive(worker.process.pid);
+ const numOfRunningWorkers = Object.keys(cluster.workers).length;
+
+ assert.strictEqual(exitCode, null);
+ assert.strictEqual(signalCode, KILL_SIGNAL);
+ assert.strictEqual(isWorkerProcessStillAlive, false);
+ assert.strictEqual(numOfRunningWorkers, 0);
+ }, 1));
+
+ // Check if the cluster was killed as well
+ cluster.on('exit', common.mustCall(() => {}, 1));
+}