Skip to content

fix flaky test TimeAndDateTest.testFutureDateWithBounds#1890

Merged
asolntsev merged 1 commit into
mainfrom
fix/flaky-date-time-test
Jul 23, 2026
Merged

fix flaky test TimeAndDateTest.testFutureDateWithBounds#1890
asolntsev merged 1 commit into
mainfrom
fix/flaky-date-time-test

Conversation

@asolntsev

Copy link
Copy Markdown
Collaborator

Example of test failure: https://github.com/datafaker-net/datafaker/actions/runs/29958635963/job/89060037790?pr=1888

The problem

The test is using variable now:

    void testFutureDateWithBounds() {
        Instant now = Instant.now();

        System.gc(); // --- GC runs at this moment ---

        Instant future = timeAndDate.future(1, TimeUnit.SECONDS);
        assertThat(future).isBetween(now, now.plusSeconds(1)); // -- `future` > `now+1s`
    }

If GC runs exactly at this moment (or JVM gets a bit slower for any reason), the future might appear later than now + 1 second.

Example of test failure: https://github.com/datafaker-net/datafaker/actions/runs/29958635963/job/89060037790?pr=1888

### The problem

The test is using variable `now`:

```
    void testFutureDateWithBounds() {
        Instant now = Instant.now();

        System.gc(); // --- GC runs at this moment ---

        Instant future = timeAndDate.future(1, TimeUnit.SECONDS);
        assertThat(future).isBetween(now, now.plusSeconds(1)); // -- `future` > `now+1s`
    }
```

If GC runs exactly at this moment (or JVM gets a bit slower for any reason), the `future` might appear later than `now + 1 second`.
@asolntsev asolntsev added this to the 3.0.0 milestone Jul 23, 2026
@asolntsev asolntsev added the bug Something isn't working label Jul 23, 2026
@asolntsev asolntsev self-assigned this Jul 23, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.55%. Comparing base (2729350) to head (074e6ba).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1890      +/-   ##
============================================
- Coverage     92.58%   92.55%   -0.03%     
+ Complexity     3572     3571       -1     
============================================
  Files           347      347              
  Lines          7051     7051              
  Branches        675      675              
============================================
- Hits           6528     6526       -2     
- Misses          364      365       +1     
- Partials        159      160       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@what-the-diff

what-the-diff Bot commented Jul 23, 2026

Copy link
Copy Markdown

PR Summary

  • Updated Test Assertion in testFutureDateWithBounds()
    The change is about updating the test validation within the function called testFutureDateWithBounds(). Previously, it was using a preset 'now' value. Now, it will use the actual, current time every time this test runs. This ensures the upper limit is always updated to the time when the test is executed.

@asolntsev
asolntsev merged commit d9669c3 into main Jul 23, 2026
17 checks passed
@asolntsev
asolntsev deleted the fix/flaky-date-time-test branch July 23, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants