Skip to content

Commit ef307bf

Browse files
committed
test: add test for worker.terminate() + timeout fns
PR-URL: #25735 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d56212e commit ef307bf

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)