Skip to content

Commit 15f6b8e

Browse files
addaleaxtargos
authored andcommitted
test: add test for worker.terminate() + timeout fns
PR-URL: #25735 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c213634 commit 15f6b8e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { Worker } = require('worker_threads');
4+
5+
// Test that calling .terminate() during a timer callback works fine.
6+
7+
for (const fn of ['setTimeout', 'setImmediate', 'setInterval']) {
8+
const worker = new Worker(`
9+
const { parentPort } = require('worker_threads');
10+
${fn}(() => {
11+
require('worker_threads').parentPort.postMessage({});
12+
while (true);
13+
});`, { eval: true });
14+
15+
worker.on('message', common.mustCallAtLeast(() => {
16+
worker.terminate();
17+
}));
18+
}

0 commit comments

Comments
 (0)