Assign each worker a worker id in parallel mode.#4813
Merged
Conversation
98ab223 to
aae81f9
Compare
Contributor
|
@forty thank you for this PR. |
juergba
reviewed
Jan 18, 2022
aae81f9 to
fc859be
Compare
Contributor
Author
|
@juergba thanks a lot for the review! I answered every comments, let me know if something does not make sense. |
juergba
reviewed
Jan 21, 2022
juergba
reviewed
Jan 21, 2022
8beaf3b to
a8ae375
Compare
juergba
reviewed
Jan 21, 2022
Contributor
|
In your issue description above: please add the keyword |
This uses a new feature from the workerpool module, which allows overriding process parameters for each process, which is why the workerpool module has been updated to the latest version (6.2.0).
a8ae375 to
368c9d2
Compare
juergba
approved these changes
Jan 21, 2022
KuznetsovRoman
pushed a commit
to gemini-testing/mocha
that referenced
this pull request
Sep 6, 2022
This uses a new feature from the workerpool module, which allows overriding process parameters for each process, which is why the workerpool module has been updated to the latest version (6.2.0).
lennonnikolas
pushed a commit
to lennonnikolas/mocha
that referenced
this pull request
Jan 24, 2026
This uses a new feature from the workerpool module, which allows overriding process parameters for each process, which is why the workerpool module has been updated to the latest version (6.2.0).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change is similar to #4463 but is cleaner as is uses a new feature from workerpool (
onCreateWorker) to override each process environment when each process is launched. I'm copying most of the description.Requirements
Description of the Change
This change addresses #4456. It adds a MOCHA_WORKER_ID environment variable that is unique for each worker, so that it may be used for by any test resources that need to use global resources (network ports, filesystem paths, etc.) but ensure that these are unique in order to avoid conflicts during parallel tests.
Alternate Designs
#4463 is an alternate way of doing the same thing, but this one is cleaner (less hacky).
#4463 suggest forkArgs might have been used, but this seem really unsafe and hacky.
Why should this be in core?
It is common for tests to use global resources like network ports, which can conflict during parallel testing. Without a feature like this in core, users would be left on their own to create a home-brewed solution (using filesystem files as signals, sockets that elect a leader in the cluster so that one process hands out all global data, a standalone cluster orchestration system), all of which add a lot of complication to writing tests. This would also be a difference when writing tests that run in series vs. parallel, as this concern would not exist (and potentially needs to be turned off) for test in series, and would add pain points when taking existing serial tests and having them run in parallel. This makes using mocha significantly less fun.
This feature takes that pain point away. For example, allocating ports would once again be trivial, using const port = 1234 + Number(process.env.MOCHA_WORKER_ID || 0).
Other parallel testing frameworks, like jest, already use this approach: jestjs/jest#2284
Benefits
This solves common pain points for developers writing tests.
Possible Drawbacks
Other than more complexity, I can't think of a drawback for the feature itself. The drawback noted by #4463 is mostly addressed by this PR, by using a cleaner way to override each process environment. Another pool implementation could easily implement a similar feature.
Applicable issues
Enter any applicable Issues here.
closes #4456
Mocha follows semantic versioning: http://semver.org
Is this a breaking change (major release)? No
Is it an enhancement (minor release)? Yes
Is it a bug fix, or does it not impact production code (patch release)? No