Skip to content

Commit

Permalink
test: add test for worker.terminate() + timeout fns
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
addaleax authored and targos committed Jan 29, 2019
1 parent c213634 commit 15f6b8e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/parallel/test-worker-terminate-timers.js
Original file line number Diff line number Diff line change
@@ -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();
}));
}

0 comments on commit 15f6b8e

Please sign in to comment.