You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by fr...@apache.org on 2026/09/16 02:31:29 UTC

(druid) branch master updated: test: fix flaky KubernetesTaskRunnerTest start tests (#20316)

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 5b1bcc11782 test: fix flaky KubernetesTaskRunnerTest start tests (#20316)
5b1bcc11782 is described below

commit 5b1bcc11782deb81bc3130c6ff9f25905bf731e3
Author: Frank Chen <fr...@outlook.com>
AuthorDate: Wed Sep 16 10:31:23 2026 +0800

    test: fix flaky KubernetesTaskRunnerTest start tests (#20316)
    
    KubernetesTaskRunner.start() schedules the cleanup of completed peon jobs on a
    background executor with a 1 ms initial delay. Whether that first cleanup runs
    before the test's verifyAll() depends on thread scheduling, so the strict mock
    intermittently reports an unexpected deleteCompletedPeonJobsOlderThan() call.
    
    Expect the cleanup call any number of times in the tests that start a runner,
    and stop every locally created runner so the executor does not outlive the test.
---
 .../k8s/overlord/KubernetesTaskRunnerTest.java     | 54 +++++++++++++++++-----
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java b/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java
index 8e49cee7fea..bfcb8a02d41 100644
--- a/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java
+++ b/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java
@@ -161,14 +161,20 @@ public class KubernetesTaskRunnerTest extends EasyMockSupport
         settableFuture
     );
 
+    expectCleanupOfCompletedJobs();
     replayAll();
 
-    runner.start();
+    try {
+      runner.start();
 
-    verifyAll();
+      verifyAll();
 
-    Assertions.assertNotNull(runner.tasks);
-    Assertions.assertEquals(1, runner.tasks.size());
+      Assertions.assertNotNull(runner.tasks);
+      Assertions.assertEquals(1, runner.tasks.size());
+    }
+    finally {
+      runner.stop();
+    }
   }
 
   @Test
@@ -247,14 +253,20 @@ public class KubernetesTaskRunnerTest extends EasyMockSupport
         settableFuture
     );
 
+    expectCleanupOfCompletedJobs();
     replayAll();
 
-    runner.start();
+    try {
+      runner.start();
 
-    verifyAll();
+      verifyAll();
 
-    Assertions.assertNotNull(runner.tasks);
-    Assertions.assertEquals(1, runner.tasks.size());
+      Assertions.assertNotNull(runner.tasks);
+      Assertions.assertEquals(1, runner.tasks.size());
+    }
+    finally {
+      runner.stop();
+    }
   }
 
   @Test
@@ -286,14 +298,32 @@ public class KubernetesTaskRunnerTest extends EasyMockSupport
     EasyMock.expect(peonClient.getPeonJobs()).andReturn(ImmutableList.of(job));
     EasyMock.expect(taskAdapter.toTask(job)).andThrow(new IOException());
 
+    expectCleanupOfCompletedJobs();
     replayAll();
 
-    runner.start();
+    try {
+      runner.start();
 
-    verifyAll();
+      verifyAll();
+
+      Assertions.assertNotNull(runner.tasks);
+      Assertions.assertEquals(0, runner.tasks.size());
+    }
+    finally {
+      runner.stop();
+    }
+  }
 
-    Assertions.assertNotNull(runner.tasks);
-    Assertions.assertEquals(0, runner.tasks.size());
+  /**
+   * {@link KubernetesTaskRunner#start()} schedules the cleanup of completed peon jobs on a background executor with
+   * an initial delay of 1 ms. Whether the first cleanup runs before {@link #verifyAll()} depends on thread scheduling,
+   * so the call must be allowed any number of times to keep the tests deterministic.
+   */
+  private void expectCleanupOfCompletedJobs()
+  {
+    EasyMock.expect(peonClient.deleteCompletedPeonJobsOlderThan(EasyMock.anyLong(), EasyMock.eq(TimeUnit.MILLISECONDS)))
+            .andReturn(0)
+            .anyTimes();
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org