diff --git a/util/src/test/java/io/kubernetes/client/CopyTest.java b/util/src/test/java/io/kubernetes/client/CopyTest.java index f5f18c84ec..059b521cf1 100644 --- a/util/src/test/java/io/kubernetes/client/CopyTest.java +++ b/util/src/test/java/io/kubernetes/client/CopyTest.java @@ -131,6 +131,21 @@ void setup() { podName = "apod"; } + // Wait (bounded) until the exec request reaches the mock server, instead of a fixed sleep + // which is flaky on slow CI runners. + private void waitForExecRequest() throws InterruptedException { + long deadline = System.currentTimeMillis() + 30000; + while (System.currentTimeMillis() < deadline + && apiServer + .findAll( + getRequestedFor( + urlPathEqualTo( + "/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec"))) + .isEmpty()) { + Thread.sleep(100); + } + } + @Test void url() { Copy copy = new Copy(client); @@ -195,7 +210,7 @@ public void run() { } }); t.start(); - Thread.sleep(2000); + waitForExecRequest(); t.interrupt(); apiServer.verify( @@ -241,7 +256,7 @@ public void run() { } }); t.start(); - Thread.sleep(2000); + waitForExecRequest(); t.interrupt(); apiServer.verify( @@ -285,7 +300,7 @@ public void run() { } }); t.start(); - Thread.sleep(2000); + waitForExecRequest(); t.interrupt(); apiServer.verify(