-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
doc: correct concurrency wording in test() documentation #60773
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
doc: correct concurrency wording in test() documentation #60773
Conversation
|
Review requested:
|
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
node/lib/internal/test_runner/test.js
Lines 989 to 1000 in 0b6ae6d
| // 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; | |
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.:
| 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). |
There was a problem hiding this comment.
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.
|
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. |
Ethan-Arrowood
left a comment
There was a problem hiding this 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.
There was a problem hiding this 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. |
There was a problem hiding this comment.
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)
| If `true`, it would run all subtests in parallel. | |
| If `true`, it would run all subtests asynchronously. |
or
| If `true`, it would run all subtests in parallel. | |
| If `true`, it would run all subtests at once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer "asynchronously"
Ethan-Arrowood
left a comment
There was a problem hiding this 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.
|
Landed in 774e564 |
This PR updates the test runner documentation for the
concurrencyoption.As discussed in #60721.
Requesting reviews from @Ethan-Arrowood and @cjihrig.