This is an automated email from the ASF dual-hosted git repository.

FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 805a5426720 test: fix flaky 
ScheduledExecutorsTest.testscheduleWithFixedDelay (#20526)
805a5426720 is described below

commit 805a5426720f492718b73f0c4de1e74db3bcd178
Author: Yahya Kisana <[email protected]>
AuthorDate: Fri Oct 9 00:02:35 2026 -0600

    test: fix flaky ScheduledExecutorsTest.testscheduleWithFixedDelay (#20526)
    
    * test: fix flaky ScheduledExecutorsTest.testscheduleWithFixedDelay
    
    * fix comment punctuation
---
 .../java/util/common/concurrent/ScheduledExecutorsTest.java   | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git 
a/processing/src/test/java/org/apache/druid/java/util/common/concurrent/ScheduledExecutorsTest.java
 
b/processing/src/test/java/org/apache/druid/java/util/common/concurrent/ScheduledExecutorsTest.java
index 8fe6eccbb4b..55f00e2a6cb 100644
--- 
a/processing/src/test/java/org/apache/druid/java/util/common/concurrent/ScheduledExecutorsTest.java
+++ 
b/processing/src/test/java/org/apache/druid/java/util/common/concurrent/ScheduledExecutorsTest.java
@@ -44,7 +44,7 @@ public class ScheduledExecutorsTest
     List<Long> taskStartTimes = new ArrayList<>();
     AtomicInteger executionCount = new AtomicInteger(0);
     CountDownLatch latch = new CountDownLatch(1);
-    long startTime = System.currentTimeMillis();
+    final long startTime = System.nanoTime();
 
     ScheduledExecutors.scheduleWithFixedDelay(
         exec,
@@ -52,7 +52,7 @@ public class ScheduledExecutorsTest
         delay,
         () -> {
           try {
-            long taskStart = System.currentTimeMillis();
+            final long taskStart = 
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
             int count = executionCount.getAndIncrement();
             synchronized (taskStartTimes) {
               taskStartTimes.add(taskStart);
@@ -78,10 +78,11 @@ public class ScheduledExecutorsTest
     Assertions.assertTrue(completed, "Should complete within timeout");
     Assertions.assertEquals(4, executionCount.get(), "Should have exactly 4 
executions");
 
-    // Verify first task starts at approximately the initial delay, in real 
life this is greater than 100ms due to overhead.
-    long firstTaskStart = taskStartTimes.get(0) - startTime;
+    // Verify first task starts at approximately the initial delay.
+    // It can fire exactly on time, so the 100ms lower bound is inclusive.
+    final long firstTaskStart = taskStartTimes.get(0);
     Assertions.assertTrue(
-        firstTaskStart > 100 && firstTaskStart < 500,
+        firstTaskStart >= 100 && firstTaskStart < 500,
         "First task should start at approximately initial delay (100ms), was: 
" + firstTaskStart
     );
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to