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

🚀 Feature: Test Sharding for CI Matrix Purposes #4958

Open
amerryma opened this issue Jan 1, 2023 · 11 comments · May be fixed by #5075
Open

🚀 Feature: Test Sharding for CI Matrix Purposes #4958

amerryma opened this issue Jan 1, 2023 · 11 comments · May be fixed by #5075
Labels
status: in discussion Let's talk about it! type: feature enhancement proposal

Comments

@amerryma
Copy link

amerryma commented Jan 1, 2023

Is your feature request related to a problem or a nice-to-have?? Please describe.
I use CodeceptJS which uses Mocha under the hood to programmatically run end-to-end tests for browsers. We've been increasing the amount of tests slowly and we're running into issues where tests are taking too long to run on a single machine.

Describe the solution you'd like
There is a concept of test sharding that I propose we add to Mocha. You can read more about this in a few other test runners such as Playwright and Codeception .

So if we had 100 tests, and I split into groups of 4, then tell one machine to execute group 1, it should execute 25 tests. One method of determining which test are part of which groups are simply running every 4th test.

We can then use the matrix strategy in Github Actions to execute each shard on a different machine in parallel.

Describe alternatives you've considered

  1. We've considered using parallel workers but the machines we're using in CI are very weak but we can spin up a lot of them.
  2. We've also considered marking each test with a grep such as "Shard 1: Test Name" and then targetting "Shard 1" with the --grep option. This gives us the flexibility to determine which tests are in which shard, but it is a large burden on the developer to need to decide this all the time.

Additional context
I've implemented this in a fork: master...discatech:mocha:test-sharding of Mocha already and would love to get some feedback on whether this is a good change for Mocha itself. I will probably continue to use my forked Mocha until we reach a decision. Thank you so much for considering this!

@davidsiu
Copy link

@amerryma Thx for working on this. It would be fantastic to get sharding support as Jest has it too and it is amazing to be able to use Github Actions Matrix support. It doesn't hurt to just make a PR and see the feedback you get. It will be one step closer to getting this merged in.

@davidsiu
Copy link

I tried your fork @amerryma and as it turns out, we have tests within a test file that depends on the previous test to run in order for it to pass. I imagine many people have also implemented their tests this way as well. Jest shards based on the entire file which won't balance the load as evenly but it helps solve the problem in a safer more general way that works with more projects. If you were to submit a PR, I would suggest an implementation that is similar to how Jest handles it using file based sharding. https://jestjs.io/docs/next/cli#--shard

@amerryma
Copy link
Author

amerryma commented May 19, 2023 via email

@GreaseCoder
Copy link

Subscribing to this. Would be great to have!

@sam-super
Copy link
Contributor

@amerryma did you make any progress?

@JimmyDaddy
Copy link

@amerryma 👀 is there any progress?

@amerryma
Copy link
Author

Hi all, I've updated my fork with the new file based strategy. @davidsiu If this is the correct direction you were thinking, I can make the PR and see if we can get this reviewed and in!

@JoshuaKGoldberg JoshuaKGoldberg changed the title Test Sharding for CI Matrix Purposes 🚀 Feature: Test Sharding for CI Matrix Purposes Dec 27, 2023
@Winify
Copy link

Winify commented Jan 2, 2024

Would be happy to see this as well!

@sam-super
Copy link
Contributor

@amerryma i think it's worth creating the PR at this point.

@amerryma amerryma linked a pull request Jan 11, 2024 that will close this issue
3 tasks
@JoshuaKGoldberg
Copy link
Member

👍 this is definitely a feature gap in Mocha compared to other test runners. I think it definitely qualifies as something we long-term would want to take in. Note that per #5027 it'll be a while before we can really take a look at something as impactful as this.

What'd be helpful first, though is to see a comparison of how other popular test runners (Codeception, Jest, Playwright, Vitest, etc.) with sharding approach it. We should make sure considerations those test runners have learned they need to contend with are accounted for in Mocha if needed.

  • How is sharding specified on the CLI and/or env variables and/or config file?
  • What sharding options do they have?
  • How does it interact with other options?

@JoshuaKGoldberg JoshuaKGoldberg added the status: in discussion Let's talk about it! label Feb 7, 2024
@JoshuaKGoldberg JoshuaKGoldberg added status: waiting for author waiting on response from OP - more information needed status: in discussion Let's talk about it! and removed status: in discussion Let's talk about it! status: waiting for author waiting on response from OP - more information needed labels Feb 27, 2024
@Sealos
Copy link

Sealos commented Oct 4, 2024

We have implemented partial sharding in our project using mochawesome, mochawesome-merge and mochawesome-report-generator. This allows us to run tests locally in parallel, and get a unified output file.

I'm happy to share more information if it might be valuable to be ported or adapted into mocha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: in discussion Let's talk about it! type: feature enhancement proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants