From 8b949efa653c0cd0ecfe8a3dd06123605dbdafed Mon Sep 17 00:00:00 2001 From: flrnd <659650+flrnd@users.noreply.github.com> Date: Tue, 3 Nov 2026 20:45:55 +0100 Subject: [PATCH] test(util): Replace sleep with latch in ExecCallbacksTest Replaces the arbitrary 30-second sleep with a latch, preserving timeout behavior while allowing the background callback to be released when the test finishes. --- .../kubernetes/client/ExecCallbacksTest.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/util/src/test/java/io/kubernetes/client/ExecCallbacksTest.java b/util/src/test/java/io/kubernetes/client/ExecCallbacksTest.java index d150eb0226..4407a7ccba 100644 --- a/util/src/test/java/io/kubernetes/client/ExecCallbacksTest.java +++ b/util/src/test/java/io/kubernetes/client/ExecCallbacksTest.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -37,18 +38,23 @@ class ExecCallbacksTest { @Test void maxTimeout() throws Exception { - Exec exec = getExec((future, io) -> Thread.sleep(30_000L)); - - long startTime = System.currentTimeMillis(); - Future promise = - exec.exec("ns-1", "pod1", null, null, null, 1_000L, true, "random-command"); - int exitCode = promise.get(10_000, TimeUnit.MILLISECONDS); - long delta = System.currentTimeMillis() - startTime; - - assertThat(delta) - .isGreaterThanOrEqualTo(1_000L) - .isLessThanOrEqualTo(10_000L); - assertThat(exitCode).isEqualTo(Integer.MAX_VALUE); + CountDownLatch release = new CountDownLatch(1); + try { + Exec exec = getExec((future, io) -> release.await()); + + long startTime = System.currentTimeMillis(); + Future promise = + exec.exec("ns-1", "pod1", null, null, null, 1_000L, true, "random-command"); + int exitCode = promise.get(10_000, TimeUnit.MILLISECONDS); + long delta = System.currentTimeMillis() - startTime; + + assertThat(delta) + .isGreaterThanOrEqualTo(1_000L) + .isLessThanOrEqualTo(10_000L); + assertThat(exitCode).isEqualTo(Integer.MAX_VALUE); + } finally { + release.countDown(); + } } @Test