Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to configure for mocha parallel ? #662

Closed
Shelvak opened this issue Aug 28, 2021 · 6 comments
Closed

How to configure for mocha parallel ? #662

Shelvak opened this issue Aug 28, 2021 · 6 comments

Comments

@Shelvak
Copy link

Shelvak commented Aug 28, 2021

Hi there, I'm trying to setup my env with parallel testing (because all my tests take about 4 minutes) and I was able to improve the time to 40seconds with last mocha version, but I can't get solidity-coverage run in parallel.

What I'm using:

  • Hardhat: 2.6.0
  • Mocha: 9.1.1
  • solidity-coverage: 0.7.16

Commands:
Parallel: npx mocha
Sequential: npx hardhat test (or npx hardhat coverage to get the coverage)

My .mocharc.json:

{
  "parallel":   true,
  "jobs":       4,
  "slow":       "1500", // 1.5s
  "full-trace": true,
  "bail":       false,
  "inspect":    true,
  "timeout":    20000,
  "exit":       true,
  "require":    ["hardhat/register", "solidity-coverage"] // tried with `solidity-coverage/api` and others but nothing happened
}

Already tried with mocha: option in the .solcover.js but it runs sequentially with npx hardhat coverage.

Mocha requiring hardhat/register starts X processes and then run everything:
image

It's more a question than an issue but it would be awesome if we can get coverage working with mocha parallel =)

Cheers.

@cgewecke
Copy link
Member

cgewecke commented Aug 28, 2021

Hi @Shelvak. There's isn't any built-in support for parallelism via mocha. There are recipes for parallelizing jobs in CI here:

(These suites are huge - in the 30-40 min range without parallelization)

The technique used there is:

  • partitioning the test suites into several groups by name
  • spinning up a process for each group and running the coverage task
  • aggregating the coverage.json files produced for each job using a tool called istanbul-combine-updated in a final step

@cgewecke
Copy link
Member

Another note - it's possible to configure the istanbul coverage report folder name in the .solcover.js options. This could be useful for a cli solution that's aggregating reports at the end.

@Shelvak
Copy link
Author

Shelvak commented Aug 28, 2021

Awesome cgewecke, thank you so much for the quick response. I think that I could hook the coverage part in each setup fork and try the merge report after everything. If I succeed I'll post here how I did it=)

@cgewecke
Copy link
Member

Ok great!

@Shelvak
Copy link
Author

Shelvak commented Oct 24, 2021

Just in case anyone arrives here looking for "the answer". I solved this with docker (because parallel hardhat network fails most of the time):

  • Create the project docker image
  • Mount a "shared" coverage directory
  • Run tests inside multiple dockers and copy the report with a custom name in shared directory
  • Combine reports within the shared dir with istanbul-combine

Run parallel test inside docker:
https://gist.github.com/Shelvak/d0c753ea373d8a6f88a30a98e503d63b

I'm 100% sure that the scripts can be improved but it's working =P

Cheers

@cgewecke
Copy link
Member

Closing in favor of #691

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants