0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-worker-terminate-microtask-loop.js
Anna Henningsen 2c9e12e496 test,worker: verify that .terminate() breaks microtask queue
PR-URL: https://github.com/nodejs/node/pull/25480
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-01-22 05:38:44 +01:00

20 lines
537 B
JavaScript

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