From f7b1971c5c973464bec824ad8133d588ca66db73 Mon Sep 17 00:00:00 2001 From: ykisana Date: Thu, 8 Oct 2026 10:23:10 -0600 Subject: [PATCH 1/2] test: fix flaky ScheduledExecutorsTest.testscheduleWithFixedDelay --- .../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 8fe6eccbb4bb..6c5ef28fd0c0 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 void testscheduleWithFixedDelay() throws Exception List 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 void testscheduleWithFixedDelay() throws Exception 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 void testscheduleWithFixedDelay() throws Exception 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 ); From 4873d916d80d980b443b9a6339e0a1f32176a3ef Mon Sep 17 00:00:00 2001 From: ykisana Date: Thu, 8 Oct 2026 10:28:28 -0600 Subject: [PATCH 2/2] fix comment punctuation --- .../java/util/common/concurrent/ScheduledExecutorsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6c5ef28fd0c0..55f00e2a6cbd 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 @@ -79,7 +79,7 @@ public void testscheduleWithFixedDelay() throws Exception Assertions.assertEquals(4, executionCount.get(), "Should have exactly 4 executions"); // Verify first task starts at approximately the initial delay. - // It can fire exactly on time, so the 100ms lower bound is inclusive, + // 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,