From 4c05154d3abfd8e54eefe8f7f6f9ea90c4bfba51 Mon Sep 17 00:00:00 2001 From: Emmanuel Oppong Date: Sun, 1 Nov 2026 08:17:53 -0600 Subject: [PATCH] Use Thread.join instead of sleep in WaitTest pollShutsDownExecutorThreadAfterReturning waited for the worker thread to stop with a hand-written loop that slept 10 ms between checks. Use Thread.join with the same 2 second limit, which waits for exactly the event the test cares about and removes the Thread.sleep. Part of #1223. --- .../test/java/io/kubernetes/client/util/wait/WaitTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/util/src/test/java/io/kubernetes/client/util/wait/WaitTest.java b/util/src/test/java/io/kubernetes/client/util/wait/WaitTest.java index a1d1eafbdc..092ca117ad 100644 --- a/util/src/test/java/io/kubernetes/client/util/wait/WaitTest.java +++ b/util/src/test/java/io/kubernetes/client/util/wait/WaitTest.java @@ -46,10 +46,7 @@ void pollShutsDownExecutorThreadAfterReturning() throws InterruptedException { // After poll returns the executor must have been shut down, so its worker thread terminates. // Allow a short grace period for the interrupt/shutdown to take effect. - long deadline = System.currentTimeMillis() + 2000; - while (worker.isAlive() && System.currentTimeMillis() < deadline) { - Thread.sleep(10); - } + worker.join(2000); assertThat(worker.isAlive()) .as("Wait.poll must shut down its executor so the worker thread is not leaked")