Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: introduce NODE_TEST_WORKER_ID for improved concurrent te… #56091

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ class FileTest extends Test {
}
}

function runTestFile(path, filesWatcher, opts) {
function runTestFile(path, filesWatcher, opts, workerId = 1) {
const watchMode = filesWatcher != null;
const testPath = path === kIsolatedProcessName ? '' : path;
const testOpts = { __proto__: null, signal: opts.signal };
const subtest = opts.root.createSubtest(FileTest, testPath, testOpts, async (t) => {
const args = getRunArgs(path, opts);
const stdio = ['pipe', 'pipe', 'pipe'];
const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' };
const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8', NODE_TEST_WORKER_ID: workerId };
if (watchMode) {
stdio.push('ipc');
env.WATCH_REPORT_DEPENDENCIES = '1';
Expand Down Expand Up @@ -724,8 +724,10 @@ function run(options = kEmptyObject) {
runFiles = () => {
root.harness.bootstrapPromise = null;
root.harness.buildPromise = null;
let workerId = 1;
return SafePromiseAllSettledReturnVoid(testFiles, (path) => {
const subtest = runTestFile(path, filesWatcher, opts);
const subtest = runTestFile(path, filesWatcher, opts, workerId);
workerId++;
filesWatcher?.runningSubtests.set(path, subtest);
return subtest;
});
Expand Down Expand Up @@ -766,6 +768,7 @@ function run(options = kEmptyObject) {

root.entryFile = resolve(testFile);
debug('loading test file:', fileURL.href);
process.env.NODE_TEST_WORKER_ID = 1;
try {
await cascadedLoader.import(fileURL, parent, { __proto__: null });
} catch (err) {
Expand Down