|
19 | 19 | import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; |
20 | 20 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; |
21 | 21 | import static org.assertj.core.api.Assertions.assertThat; |
| 22 | +import static org.awaitility.Awaitility.await; |
22 | 23 |
|
23 | 24 | import com.github.tomakehurst.wiremock.core.Admin; |
24 | 25 | import com.github.tomakehurst.wiremock.extension.Parameters; |
|
38 | 39 | import io.kubernetes.client.openapi.models.V1PodList; |
39 | 40 | import io.kubernetes.client.util.ClientBuilder; |
40 | 41 | import io.kubernetes.client.util.generic.GenericKubernetesApi; |
| 42 | +import java.time.Duration; |
41 | 43 | import java.util.Collections; |
42 | 44 | import java.util.concurrent.Semaphore; |
43 | 45 | import org.junit.jupiter.api.Test; |
@@ -167,21 +169,27 @@ void informerInjection() throws InterruptedException { |
167 | 169 | getCount.acquire(2); |
168 | 170 | watchCount.acquire(2); |
169 | 171 |
|
170 | | - // Add a small delay to ensure WireMock has finished recording the requests |
171 | | - Thread.sleep(100); |
172 | | - |
173 | | - apiServer.verify( |
174 | | - 1, |
175 | | - getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false"))); |
176 | | - apiServer.verify( |
177 | | - getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true"))); |
178 | | - apiServer.verify( |
179 | | - 1, |
180 | | - getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")) |
181 | | - .withQueryParam("watch", equalTo("false"))); |
182 | | - apiServer.verify( |
183 | | - getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")) |
184 | | - .withQueryParam("watch", equalTo("true"))); |
| 172 | + // Use Awaitility to poll until WireMock has recorded the requests |
| 173 | + await() |
| 174 | + .atMost(Duration.ofSeconds(5)) |
| 175 | + .pollInterval(Duration.ofMillis(50)) |
| 176 | + .untilAsserted( |
| 177 | + () -> { |
| 178 | + apiServer.verify( |
| 179 | + 1, |
| 180 | + getRequestedFor(urlPathEqualTo("/api/v1/pods")) |
| 181 | + .withQueryParam("watch", equalTo("false"))); |
| 182 | + apiServer.verify( |
| 183 | + getRequestedFor(urlPathEqualTo("/api/v1/pods")) |
| 184 | + .withQueryParam("watch", equalTo("true"))); |
| 185 | + apiServer.verify( |
| 186 | + 1, |
| 187 | + getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")) |
| 188 | + .withQueryParam("watch", equalTo("false"))); |
| 189 | + apiServer.verify( |
| 190 | + getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")) |
| 191 | + .withQueryParam("watch", equalTo("true"))); |
| 192 | + }); |
185 | 193 |
|
186 | 194 | assertThat(new Lister<>(podInformer.getIndexer()).list()).hasSize(1); |
187 | 195 | assertThat(new Lister<>(configMapInformer.getIndexer()).list()).hasSize(1); |
|
0 commit comments