Skip to content

Commit 06b5ef3

Browse files
cjihrigtargos
authored andcommitted
test: terminate cluster worker in infinite loop
Verify that worker.process.kill() can terminate a cluster worker stuck in an infinite loop. PR-URL: #23165 Fixes: #22703 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 5836b9f commit 06b5ef3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const common = require('../common');
3+
const cluster = require('cluster');
4+
const assert = require('assert');
5+
6+
if (cluster.isMaster) {
7+
const worker = cluster.fork();
8+
9+
worker.on('online', common.mustCall(() => {
10+
// Use worker.process.kill() instead of worker.kill() because the latter
11+
// waits for a graceful disconnect, which will never happen.
12+
worker.process.kill();
13+
}));
14+
15+
worker.on('exit', common.mustCall((code, signal) => {
16+
assert.strictEqual(code, null);
17+
assert.strictEqual(signal, 'SIGTERM');
18+
}));
19+
} else {
20+
while (true) {}
21+
}

0 commit comments

Comments
 (0)