diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractInterceptorTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractInterceptorTest.java index 2f5053049ca..18385888034 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractInterceptorTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractInterceptorTest.java @@ -41,6 +41,7 @@ public abstract class AbstractInterceptorTest { + private static final Duration FUTURE_COMPLETION_TIME = Duration.of(10, ChronoUnit.SECONDS); private static DefaultMockServer server; @BeforeEach @@ -179,6 +180,7 @@ public CompletableFuture afterFailure(BasicBuilder builder, HttpRespons @DisplayName("afterConnectionFailure, invoked when remote server offline") public void afterConnectionFailureRemoteOffline() { // Given + final int originalPort = server.getPort(); server.shutdown(); final CountDownLatch connectionFailureCallbackInvoked = new CountDownLatch(1); final HttpClient.Builder builder = getHttpClientFactory().newBuilder() @@ -187,6 +189,8 @@ public void afterConnectionFailureRemoteOffline() { @Override public void afterConnectionFailure(HttpRequest request, Throwable failure) { connectionFailureCallbackInvoked.countDown(); + server = newMockServer(); + server.start(originalPort); // Need to restart on the original port as we can't alter the request during retry. } }); // When @@ -196,7 +200,7 @@ public void afterConnectionFailure(HttpRequest request, Throwable failure) { .uri(server.url("/not-found")).build(), String.class); // Then - assertThat(response).failsWithin(Duration.of(30, ChronoUnit.SECONDS)); + assertThat(response).succeedsWithin(FUTURE_COMPLETION_TIME); assertThat(connectionFailureCallbackInvoked).extracting(CountDownLatch::getCount).isEqualTo(0L); } } @@ -214,8 +218,8 @@ public void afterConnectionFailureRetry() { @Override public void afterConnectionFailure(HttpRequest request, Throwable failure) { server = newMockServer(); - server.expect().withPath("/intercepted-url").andReturn(200, "This works").once(); server.start(originalPort); // Need to restart on the original port as we can't alter the request during retry. + server.expect().withPath("/intercepted-url").andReturn(200, "This works").once(); } @Override @@ -230,7 +234,7 @@ public void after(HttpRequest request, HttpResponse response, Consumer