Skip to content

Commit 48f3a1f

Browse files
committed
flake: reduce controller-test flakiness via awaitilities
1 parent b641fd3 commit 48f3a1f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

util/src/test/java/io/kubernetes/client/informer/cache/ControllerTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@
2121
import io.kubernetes.client.openapi.models.V1Pod;
2222
import io.kubernetes.client.openapi.models.V1PodList;
2323
import io.kubernetes.client.util.Watch;
24+
import java.time.Duration;
2425
import java.util.Arrays;
25-
import java.util.concurrent.atomic.AtomicBoolean;
2626
import java.util.concurrent.atomic.AtomicInteger;
27+
import org.awaitility.Awaitility;
28+
import org.hamcrest.core.IsEqual;
2729
import org.junit.Test;
2830

2931
public class ControllerTest {
3032

3133
@Test
32-
public void testControllerProcessDeltas() throws InterruptedException {
34+
public void testControllerProcessDeltas() {
3335

3436
AtomicInteger receivingDeltasCount = new AtomicInteger(0);
3537
V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
@@ -40,8 +42,6 @@ public void testControllerProcessDeltas() throws InterruptedException {
4042
new V1PodList().metadata(new V1ListMeta()).items(Arrays.asList(foo1, foo2, foo3));
4143
DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, new Cache());
4244

43-
AtomicBoolean runOnce = new AtomicBoolean(false);
44-
4545
ListerWatcher<V1Pod, V1PodList> listerWatcher =
4646
new MockRunOnceListerWatcher<V1Pod, V1PodList>(
4747
podList, new Watch.Response<V1Pod>(EventType.MODIFIED.name(), foo3));
@@ -58,12 +58,12 @@ public void testControllerProcessDeltas() throws InterruptedException {
5858
controllerThread.setDaemon(true);
5959
controllerThread.start();
6060

61-
// sleep 1s for processing all the deltas
62-
Thread.sleep(1000);
63-
6461
try {
62+
Awaitility.await()
63+
.pollInterval(Duration.ofSeconds(1))
64+
.timeout(Duration.ofSeconds(5))
65+
.untilAtomic(receivingDeltasCount, IsEqual.equalTo(4));
6566
assertEquals(4, receivingDeltasCount.get());
66-
6767
} catch (Throwable t) {
6868
throw new RuntimeException(t);
6969
} finally {

0 commit comments

Comments
 (0)