Skip to content

Conversation

@azadgupta1
Copy link
Contributor

This PR updates the test runner documentation for the concurrency option.

  • Replaces “application thread” with “test process”
  • Clarifies that concurrency is achieved using child processes, not threads
  • Changes “parallel” to “concurrent” for accuracy

As discussed in #60721.

Requesting reviews from @Ethan-Arrowood and @cjihrig.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. test_runner Issues and PRs related to the test runner subsystem. labels Nov 18, 2025
doc/api/test.md Outdated
properties are supported:
* `concurrency` {number|boolean} If a number is provided,
then that many tests would run in parallel within the application thread.
then that many tests would run concurrently within the test process.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Clarifies that concurrency is achieved using child processes, not threads

I don't think it clarifies, specifying concurrency only affects the current thread, IMO talking about "process" muddies the water.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also not always correct: isolation none runs the tests in the main process (instead of a dedicated test process).

"Thread" is indeed wrong though, and that affects shared globals, so maybe that should be corrected. I think there may be a circumstance where it uses threads instead of processes though, but that may not be the case (anymore?). I'd have to check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case where test({ concurrency: true }, …) would result in creating multiple threads / processes? I don't think that's a thing, I feel like we're talking about different things.

Copy link
Member

@JakobJingleheimer JakobJingleheimer Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case where test({ concurrency: true }, …) would result in creating multiple threads / processes?

Processes: no, never (each test file gets its own process though)

Threads: I believe it uses Promise.allSettled when concurrency: true (when concurrency: number, I think it uses threads)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Promise.allSettled would make more sense, because that runs in the same thread. Test files written in JS are no different for other JS files: if making a JS file multi-threaded was as easy as setting a boolean value, we would not reserve it only to tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its just a queue of promises

// If there is enough available concurrency to run the test now, then do
// it. Otherwise, return a Promise to the caller and mark the test as
// pending for later execution.
this.parent.unfinishedSubtests.add(this);
this.reporter.enqueue(this.nesting, this.loc, this.name, this.reportedType);
if (this.root.harness.buildPromise || !this.parent.hasConcurrency()) {
const deferred = PromiseWithResolvers();
deferred.test = this;
this.parent.addPendingSubtest(deferred);
return deferred.promise;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to be clear we are explicitly talking about the concurrency option for a suite or test function. Such as suite('foo', { concurrency: number | boolean }, () => {}); or test('bar', { concurrency: number | boolean }, () => {});

The concurrency option for run() or the CLI args does use processes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to be clear we are explicitly talking about the concurrency option for a suite or test function.

I know 🙂

It would probably be easiest to find the original PR that introduced it (there was specific discussion around Boolean vs number, so the answer will be there).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO if we think talking about "thread" is bad because there's only one thread, it makes no sense to replace it with "process", for the same reason. Maybe we can find an alternative wording, e.g.:

Suggested change
then that many tests would run concurrently within the test process.
then that many tests would run asynchronously (they are still managed by the single-threaded event loop).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO if we think talking about "thread" is bad because there's only one thread, it makes no sense to replace it with "process", for the same reason.

I better understand your reasoning now. I think your proposed wording is much clearer.

@azadgupta1
Copy link
Contributor Author

Thanks for the feedback!

I see your point. I want to make the wording correct, but I'm not fully sure what the best replacement would be. Could you suggest the wording you think fits here? I’ll update the PR accordingly.

Copy link
Contributor

@Ethan-Arrowood Ethan-Arrowood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this lgtm and I believe is a more accurate wording for how the test runner actually works.

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an explicit -1 since this has an approval.

I disagree with using concurrently within the test process, if anything that makes it sound like there would be threads involved, at least the current wording is clearer that this isn't the case. I have a suggestion in #60773 (comment), I'm open to alternatives to unblock this

* `concurrency` {number|boolean|null} If a number is provided,
then that many tests would run in parallel within the application thread.
then that many tests would run asynchronously (they are still managed by the single-threaded event loop).
If `true`, it would run all subtests in parallel.
Copy link
Contributor

@aduh95 aduh95 Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also get rid of the other mentions of "parallel" (non blocking, can also happen in a follow up PR)

Suggested change
If `true`, it would run all subtests in parallel.
If `true`, it would run all subtests asynchronously.

or

Suggested change
If `true`, it would run all subtests in parallel.
If `true`, it would run all subtests at once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer "asynchronously"

Copy link
Contributor

@Ethan-Arrowood Ethan-Arrowood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! ty all for quick iteration here.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Nov 18, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 20, 2025
@nodejs-github-bot nodejs-github-bot merged commit 774e564 into nodejs:main Nov 20, 2025
27 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 774e564

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. doc Issues and PRs related to the documentations. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants