Skip to content

Commit 3411067

Browse files
Fix flaky CopyTest: wait for exec request instead of fixed sleep
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
1 parent 5c802de commit 3411067

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎util/src/test/java/io/kubernetes/client/CopyTest.java‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ void setup() {
131131
podName = "apod";
132132
}
133133

134+
// Wait (bounded) until the exec request reaches the mock server, instead of a fixed sleep
135+
// which is flaky on slow CI runners.
136+
private void waitForExecRequest() throws InterruptedException {
137+
long deadline = System.currentTimeMillis() + 30000;
138+
while (System.currentTimeMillis() < deadline
139+
&& apiServer
140+
.findAll(
141+
getRequestedFor(
142+
urlPathEqualTo(
143+
"/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")))
144+
.isEmpty()) {
145+
Thread.sleep(100);
146+
}
147+
}
148+
134149
@Test
135150
void url() {
136151
Copy copy = new Copy(client);
@@ -195,7 +210,7 @@ public void run() {
195210
}
196211
});
197212
t.start();
198-
Thread.sleep(2000);
213+
waitForExecRequest();
199214
t.interrupt();
200215

201216
apiServer.verify(
@@ -241,7 +256,7 @@ public void run() {
241256
}
242257
});
243258
t.start();
244-
Thread.sleep(2000);
259+
waitForExecRequest();
245260
t.interrupt();
246261

247262
apiServer.verify(
@@ -285,7 +300,7 @@ public void run() {
285300
}
286301
});
287302
t.start();
288-
Thread.sleep(2000);
303+
waitForExecRequest();
289304
t.interrupt();
290305

291306
apiServer.verify(

0 commit comments

Comments
 (0)