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

test: update clock tests to run deterministically #6828

Merged

Conversation

divyesh87
Copy link
Contributor

Motivation

Clock tests at clock.test.ts keep failing from time to time due to edge cases arising from the use of Date.now
This aims to fix that.

Description

This change overrides the system time before each test case to make the tests run deterministically.

Closes #6734

@CLAassistant
Copy link

CLAassistant commented May 29, 2024

CLA assistant check
All committers have signed the CLA.

@divyesh87 divyesh87 changed the title fix: Failing clock tests fix: failing clock tests May 29, 2024
Comment on lines +91 to +93
beforeEach(() => {
vi.setSystemTime(genesisTime * 1000);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using vi.useFakeTimers({now: Date.now()}); that config now is enough to make the tests deterministic. If any regression detected we should try to hardcode value now to a static value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that config now is enough to make the tests deterministic

but the test is not deterministic, see #6734 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another failed run on unstable, we should merge this

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just need to fix the lint issues

packages/validator/test/unit/utils/clock.test.ts Outdated Show resolved Hide resolved
@nflaig nflaig changed the title fix: failing clock tests test: failing clock tests Jun 7, 2024
@nflaig nflaig marked this pull request as ready for review June 7, 2024 17:46
@nflaig nflaig requested a review from a team as a code owner June 7, 2024 17:46
@nflaig nflaig changed the title test: failing clock tests test: update clock tests to run deterministically Jun 7, 2024
@nflaig nflaig requested a review from nazarhussain June 7, 2024 17:48
Copy link

codecov bot commented Jun 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.19%. Comparing base (95ce044) to head (10428a8).
Report is 21 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #6828      +/-   ##
============================================
- Coverage     62.21%   62.19%   -0.02%     
============================================
  Files           571      571              
  Lines         60017    60021       +4     
  Branches       1975     1973       -2     
============================================
- Hits          37338    37333       -5     
- Misses        22636    22645       +9     
  Partials         43       43              

Copy link
Member

@matthewkeil matthewkeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!! 🎸

@matthewkeil matthewkeil enabled auto-merge (squash) June 17, 2024 14:58
@matthewkeil matthewkeil removed the request for review from nazarhussain June 17, 2024 14:58
@matthewkeil matthewkeil merged commit 7e35c92 into ChainSafe:unstable Jun 17, 2024
21 checks passed
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.20.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit test fails at clock.test.ts from time to time
6 participants