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>
This commit is contained in:
parent
1b11824f51
commit
2c9e12e496
19
test/parallel/test-worker-terminate-microtask-loop.js
Normal file
19
test/parallel/test-worker-terminate-microtask-loop.js
Normal file
@ -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);
|
||||||
|
}));
|
Loading…
x
Reference in New Issue
Block a user