0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-worker-terminate-timers.js
Anna Henningsen ef307bfd17
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>
2019-01-29 19:20:13 +01:00

19 lines
522 B
JavaScript

'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();
}));
}