From 074e6ba15f178b64c000cf79b8cb62e1f27d41b5 Mon Sep 17 00:00:00 2001 From: Andrei Solntsev Date: Thu, 23 Jul 2026 11:46:54 +0300 Subject: [PATCH] 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`. --- src/test/java/net/datafaker/providers/base/TimeAndDateTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/net/datafaker/providers/base/TimeAndDateTest.java b/src/test/java/net/datafaker/providers/base/TimeAndDateTest.java index 62ae8c171..461ea2ab0 100644 --- a/src/test/java/net/datafaker/providers/base/TimeAndDateTest.java +++ b/src/test/java/net/datafaker/providers/base/TimeAndDateTest.java @@ -36,7 +36,7 @@ void testFutureDate() { void testFutureDateWithBounds() { Instant now = Instant.now(); Instant future = timeAndDate.future(1, TimeUnit.SECONDS); - assertThat(future).isBetween(now, now.plusSeconds(1)); + assertThat(future).isBetween(now, Instant.now().plusSeconds(1)); } @RepeatedTest(100)