Skip to content

Commit

Permalink
test,worker: verify that .terminate() breaks microtask queue
Browse files Browse the repository at this point in the history
PR-URL: #25480
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and danbev committed Jan 22, 2019
1 parent 1b11824 commit 2c9e12e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/parallel/test-worker-terminate-microtask-loop.js
@@ -0,0 +1,19 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');

// Verify that `.terminate()` interrupts the microtask queue.

const worker = new Worker(`
function loop() { Promise.resolve().then(loop); } loop();
require('worker_threads').parentPort.postMessage('up');
`, { eval: true });

worker.once('message', common.mustCall(() => {
setImmediate(() => worker.terminate());
}));

worker.once('exit', common.mustCall((code) => {
assert.strictEqual(code, 1);
}));

0 comments on commit 2c9e12e

Please sign in to comment.