question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for parallel tests

See original GitHub issue

We are working on adding support for parallel tests in Hardhat and one of our concerns is how it works with hardhat-gas-reporter. I tested it locally and found some errors when Mocha executes in parallel.

The first problem looks like this:

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined

And it’s thrown here. This is weird and I couldn’t find the reason why it happens. But I did find that adding this line in the overridden subtask fixes the problem:

       if (hre.network.name === HARDHAT_NETWORK_NAME || options.fast){
         const wrappedDataProvider= new EGRDataCollectionProvider(hre.network.provider,mochaConfig);
+        await hre.network.provider.send("eth_blockNumber");
         hre.network.provider = new BackwardsCompatibilityProviderAdapter(wrappedDataProvider);
 
         const asyncProvider = new EGRAsyncApiProvider(hre.network.provider);

That call forces the existing provider to be initialized, and so the function exists. Obviously, this is not the right fix, but it’s a hint that the problem could be related to the custom providers created by the plugin.

The second problem looks like this:

  1) Uncaught error outside test suite:
     Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Contract'
    |     property 'location' -> object with constructor 'SourceLocation'
    |     property 'file' -> object with constructor 'SourceFile'
    |     property 'contracts' -> object with constructor 'Array'
    --- index 0 closes the circle

I’m more confident about what’s causing this one. I think it’s this line in the plugin:

        mochaConfig.reporterOptions.provider = asyncProvider;

My guess is that Mocha stringifies the config for some reason (maybe to send it to the workers it creates to run the tests?) and then an error is thrown because the provider is a non-serializable object.


All that being said, I think a first step would be to just detect that parallel mode is being used and throw a proper error. That can be done like this:

    if (args.parallel === true) {
      throw new HardhatPluginError("hardhat-gas-reporter", `Parallel tests are not supported`);
    }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cgeweckecommented, Feb 15, 2022

This is published (with suggested revision to use a warning instead of an error) in 1.0.8.

Just lmk if you see this not working for some reason…thanks again for advice, etc 😃

1reaction
alcuadradocommented, Feb 12, 2022

Is there a task hook (executed before test) where a plugin that is wrapping the provider could initialize the globally injected provider?

I don’t think that’s possible right now (cc @alcuadrado)

Confirming this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parallelization | Cypress Documentation
Cypress can run recorded tests in parallel across multiple machines since version 3.1.0. While parallel tests can also technically run on a single...
Read more >
A complete guide to parallel testing - HeadSpin
Testing platforms like Appium, Robotium, HeadSpin, and Espresso efficiently support parallel testing on multiple mobile devices.
Read more >
What is Parallel Testing and How Does it Work? - Semaphore CI
Parallel testing is an indispensable technique for reducing wait times. And mastering it is key to getting the most out of CI/CD.
Read more >
Parallel Testing: The Essential Guide - BrowserStack
The cloud allows parallel testing and supports integrations with popular CI/CD tools such as Jira, Jenkins, TeamCity, Travis CI, to ensure ...
Read more >
Parallel Testing | TestComplete Documentation
Parallel testing is testing multiple applications or components of the application concurrently, to reduce the test time. Parallel tests consist of two or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found