From ccaef5a7480fb033f028d62913f3e9e18b318507 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 27 Jan 2019 16:06:30 +0100 Subject: [PATCH] test: add test for `worker.terminate()` + timeout fns --- test/parallel/test-worker-terminate-timers.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/parallel/test-worker-terminate-timers.js diff --git a/test/parallel/test-worker-terminate-timers.js b/test/parallel/test-worker-terminate-timers.js new file mode 100644 index 00000000000000..62360a6cdbfc18 --- /dev/null +++ b/test/parallel/test-worker-terminate-timers.js @@ -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(); + })); +}