Skip to content

Commit

Permalink
speculative changes for integration test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Dec 5, 2022
1 parent 9b248dd commit 7fc7a24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Expand Up @@ -240,7 +240,7 @@ public OkHttpClientImpl(OkHttpClient client, OkHttpClientBuilderImpl builder) {

@Override
public void close() {
LOG.debug("Shutting down dispatcher " + this.httpClient.dispatcher(), new Exception());
LOG.info("Shutting down dispatcher " + this.httpClient.dispatcher(), new Exception());
ConnectionPool connectionPool = httpClient.connectionPool();
Dispatcher dispatcher = httpClient.dispatcher();
ExecutorService executorService = httpClient.dispatcher() != null ? httpClient.dispatcher().executorService() : null;
Expand All @@ -260,6 +260,7 @@ public void close() {

private CompletableFuture<HttpResponse<AsyncBody>> sendAsync(HttpRequest request,
Function<BufferedSource, AsyncBody> handler) {
Exception exception = new Exception();
CompletableFuture<HttpResponse<AsyncBody>> future = new CompletableFuture<>();
Call call = httpClient.newCall(requestBuilder((StandardHttpRequest) request).build());
try {
Expand All @@ -278,13 +279,13 @@ public void onResponse(Call call, Response response) throws IOException {
public void onFailure(Call call, IOException e) {
Throwable t = e;
if (e instanceof InterruptedIOException && e.getCause() instanceof RejectedExecutionException) {
t = wrapRejected((RejectedExecutionException) e.getCause());
t = wrapRejected((RejectedExecutionException) e.getCause(), exception);
}
future.completeExceptionally(t);
}
});
} catch (RejectedExecutionException e) {
throw wrapRejected(e);
throw wrapRejected(e, exception);
}
future.whenComplete((r, t) -> {
if (future.isCancelled()) {
Expand All @@ -294,7 +295,8 @@ public void onFailure(Call call, IOException e) {
return future;
}

private KubernetesClientException wrapRejected(RejectedExecutionException e) {
private KubernetesClientException wrapRejected(RejectedExecutionException e, Exception callStack) {
LOG.info("Attempting to run against an already shutdown dispatcher " + this.httpClient.dispatcher(), callStack);
return new KubernetesClientException("The okhttp client executor has been shutdown. "
+ "More than likely this is because the KubernetesClient.close method (see debug logging) has been called "
+ "- please ensure that is intentional. Dispatcher: " + this.httpClient.dispatcher(), e);
Expand Down
Expand Up @@ -39,9 +39,6 @@

public class KubernetesNamespacedTestExtension implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback {

private static final ExtensionContext.Namespace EXT_NAMESPACE = ExtensionContext.Namespace
.create(KubernetesNamespacedTestExtension.class);

@Override
public void beforeAll(ExtensionContext context) throws Exception {
final KubernetesClient client = new KubernetesClientBuilder().build();
Expand Down Expand Up @@ -82,7 +79,9 @@ static KubernetesClient getClient(ExtensionContext context) {
}

private static ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(EXT_NAMESPACE);
ExtensionContext.Namespace namespace = ExtensionContext.Namespace.create(KubernetesNamespacedTestExtension.class,
context.getRequiredTestClass());
return context.getRoot().getStore(namespace);
}

/**
Expand Down Expand Up @@ -111,11 +110,11 @@ private static Namespace initNamespace(KubernetesClient client) {
.withName("default")
.waitUntilCondition(sa -> sa != null && sa.getSecrets() != null
&& sa.getSecrets().stream().anyMatch(s -> s.getName().matches("default-token.+")),
5, TimeUnit.SECONDS)
30, TimeUnit.SECONDS)
.getSecrets();
for (ObjectReference secret : secrets) {
client.secrets().inNamespace(namespace.getMetadata().getName()).withName(secret.getName())
.waitUntilCondition(Objects::nonNull, 5, TimeUnit.SECONDS);
.waitUntilCondition(Objects::nonNull, 30, TimeUnit.SECONDS);
}
}
return namespace;
Expand Down
Expand Up @@ -30,6 +30,7 @@ public void beforeAll(ExtensionContext context) {
final LoadKubernetesManifests annotation = context.getRequiredTestClass()
.getAnnotation(LoadKubernetesManifests.class);
final KubernetesClient kc = getClient(context);
System.out.println(context.getDisplayName() + " load beforeall " + kc);
for (String resource : annotation.value()) {
kc.load(context.getRequiredTestClass().getResourceAsStream(resource)).create();
}
Expand All @@ -41,6 +42,7 @@ public void afterAll(ExtensionContext context) {
.getAnnotation(LoadKubernetesManifests.class);
if (annotation.deleteAfterTest()) {
final KubernetesClient kc = getClient(context);
System.out.println(context.getDisplayName() + " load afterall " + kc);
for (String resource : annotation.value()) {
kc.load(context.getRequiredTestClass().getResourceAsStream(resource))
.withGracePeriod(annotation.deleteGracePeriod()).delete();
Expand Down

0 comments on commit 7fc7a24

Please sign in to comment.