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 <[email protected]>
  • Loading branch information
addaleax committed Jan 23, 2019
1 parent d6b50c6 commit aa9a86a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/parallel/test-worker-terminate-microtask-loop.js
Original file line number Diff line number Diff line change
@@ -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 aa9a86a

Please sign in to comment.