Skip to content
Merged
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ changes:
* `options` {Object} Configuration options for the test. The following
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.

If `true`, all scheduled asynchronous tests run concurrently within the
thread. If `false`, only one test runs at a time.
If unspecified, subtests inherit this value from their parent.
Expand Down Expand Up @@ -3882,7 +3882,7 @@ changes:
* `options` {Object} Configuration options for the subtest. The following
properties are supported:
* `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 concurrently within the test process.
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"

If `false`, it would only run one test at a time.
If unspecified, subtests inherit this value from their parent.
Expand Down
Loading