mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

Having an experimental feature behind a flag makes change if we are expecting significant breaking changes to its API. Since the Worker API has been essentially stable since its initial introduction, and no noticeable doubt about possibly not keeping the feature around has been voiced, removing the flag and thereby reducing the barrier to experimentation, and consequently receiving feedback on the implementation, seems like a good idea. PR-URL: https://github.com/nodejs/node/pull/25361 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
// This test checks that Worker has correct exit codes on parent side
|
|
// in multiple situations.
|
|
|
|
const assert = require('assert');
|
|
const worker = require('worker_threads');
|
|
const { Worker, parentPort } = worker;
|
|
|
|
const testCases = require('../fixtures/process-exit-code-cases');
|
|
|
|
// Do not use isMainThread so that this test itself can be run inside a Worker.
|
|
if (!process.env.HAS_STARTED_WORKER) {
|
|
process.env.HAS_STARTED_WORKER = 1;
|
|
parent();
|
|
} else {
|
|
if (!parentPort) {
|
|
console.error('Parent port must not be null');
|
|
process.exit(100);
|
|
return;
|
|
}
|
|
parentPort.once('message', (msg) => testCases[msg].func());
|
|
}
|
|
|
|
function parent() {
|
|
const test = (arg, name = 'worker', exit, error = null) => {
|
|
const w = new Worker(__filename);
|
|
w.on('exit', common.mustCall((code) => {
|
|
assert.strictEqual(
|
|
code, exit,
|
|
`wrong exit for ${arg}-${name}\nexpected:${exit} but got:${code}`);
|
|
console.log(`ok - ${arg} exited with ${exit}`);
|
|
}));
|
|
if (error) {
|
|
w.on('error', common.mustCall((err) => {
|
|
console.log(err);
|
|
assert(error.test(err),
|
|
`wrong error for ${arg}\nexpected:${error} but got:${err}`);
|
|
}));
|
|
}
|
|
w.postMessage(arg);
|
|
};
|
|
|
|
testCases.forEach((tc, i) => test(i, tc.func.name, tc.result, tc.error));
|
|
}
|