test: add test for worker.terminate()
+ timeout fns
PR-URL: https://github.com/nodejs/node/pull/25735 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d56212e6ef
commit
ef307bfd17
18
test/parallel/test-worker-terminate-timers.js
Normal file
18
test/parallel/test-worker-terminate-timers.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const { Worker } = require('worker_threads');
|
||||||
|
|
||||||
|
// Test that calling .terminate() during a timer callback works fine.
|
||||||
|
|
||||||
|
for (const fn of ['setTimeout', 'setImmediate', 'setInterval']) {
|
||||||
|
const worker = new Worker(`
|
||||||
|
const { parentPort } = require('worker_threads');
|
||||||
|
${fn}(() => {
|
||||||
|
require('worker_threads').parentPort.postMessage({});
|
||||||
|
while (true);
|
||||||
|
});`, { eval: true });
|
||||||
|
|
||||||
|
worker.on('message', common.mustCallAtLeast(() => {
|
||||||
|
worker.terminate();
|
||||||
|
}));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user