mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

Do not emit `'exit'` events caused by recursively stopping all running Workers from inside the `process.exit()` call. PR-URL: https://github.com/nodejs/node/pull/32546 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
23 lines
796 B
JavaScript
23 lines
796 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { spawnSync } = require('child_process');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
// Test that 'exit' events for Workers are not received when the main thread
|
|
// terminates itself through process.exit().
|
|
|
|
if (process.argv[2] !== 'child') {
|
|
const {
|
|
stdout, stderr, status
|
|
} = spawnSync(process.execPath, [__filename, 'child'], { encoding: 'utf8' });
|
|
assert.strictEqual(stderr, '');
|
|
assert.strictEqual(stdout, '');
|
|
assert.strictEqual(status, 0);
|
|
} else {
|
|
const nestedWorker = new Worker('setInterval(() => {}, 100)', { eval: true });
|
|
// This console.log() should never fire.
|
|
nestedWorker.on('exit', () => console.log('exit event received'));
|
|
nestedWorker.on('online', () => process.exit());
|
|
}
|