Skip to content

Commit d9669c3

Browse files
committed
fix flaky test TimeAndDateTest.testFutureDateWithBounds
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`.
1 parent 2729350 commit d9669c3

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/test/java/net/datafaker/providers/base/TimeAndDateTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void testFutureDate() {
3636
void testFutureDateWithBounds() {
3737
Instant now = Instant.now();
3838
Instant future = timeAndDate.future(1, TimeUnit.SECONDS);
39-
assertThat(future).isBetween(now, now.plusSeconds(1));
39+
assertThat(future).isBetween(now, Instant.now().plusSeconds(1));
4040
}
4141

4242
@RepeatedTest(100)

0 commit comments

Comments
 (0)