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

Sporadic test failures when running hardhat test due to incorrect usage of chai matchers when hardhat >= 2.21.0 #5036

Closed
gzliudan opened this issue Mar 26, 2024 · 3 comments · Fixed by gzliudan/MatrixProtocol#1
Assignees

Comments

@gzliudan
Copy link

Version of Hardhat

=2.21.0

What happened?

  • pass all tests when hardhat < 2.21.0
  • fail some tests when hardhat >= 2.21.0

Minimal reproduction steps

git clone https://github.com/gzliudan/MatrixProtocol.git
cd MatrixProtocol
# setup hardhat's version in package.json 
yarn
yarn make

The test will cost about 10 minutes.

Search terms

No response

@fvictorio fvictorio transferred this issue from NomicFoundation/hardhat Mar 26, 2024
@Wodann Wodann self-assigned this Mar 27, 2024
@Wodann Wodann changed the title bug: some tests fail when hardhat >= 2.21.0 Sporadic test failures when running hardhat test due to incorrect usage of chai matchers when hardhat >= 2.21.0 Mar 27, 2024
@Wodann Wodann transferred this issue from NomicFoundation/edr Mar 27, 2024
@Wodann
Copy link
Collaborator

Wodann commented Mar 27, 2024

This is not a bug in Hardhat but a result of incorrect usage of mocha + chai. Multiple promises were running in the background, resulting in parallel execution of test assertions. This results in the sporadic failures displayed when I tested your repository.

I fixed the problem by making changes to your tests. After these changes, I could no longer reproduce the sporadic failures.

For anyone else experiencing sporadic failures when upgrading to Hardhat >= 2.21.0; please make sure that you're:

  • not passing an async function or async callback to the describe function. It's only intended to be used synchronously, even though it silently accepts async callbacks (also see this issue)
  • ensure you await all async calls

@Wodann Wodann closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
@gzliudan
Copy link
Author

I test in 3 VMs with your PR, but still has some tests failed each time. My test environment:

  • Ubuntu: 22.04.04
  • node: v18.20.0 and v18.19.1

@gzliudan gzliudan reopened this Mar 28, 2024
@gzliudan
Copy link
Author

I fixed this problem according to your suggestions. Thanks for your kindly help again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants