Skip to content

Commit 84dffac

Browse files
committed
Fix ApacheHttpAsyncClientTest cleanup firing per @nested container
AutoCleanupExtension.deferAfterAll(...) registers callbacks on a static extension whose afterAll() fires once per @nested class container, so clients were closed after the first nested class finished, causing all tests in subsequent nested classes to fail with CancellationException. Use a plain @afterall method on the outer class instead — it runs only once, after all nested classes complete.
1 parent d9fba53 commit 84dffac

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

  • instrumentation/apache-httpasyncclient-4.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/v4_1

instrumentation/apache-httpasyncclient-4.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/v4_1/ApacheHttpAsyncClientTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient.v4_1;
77

8-
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
98
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
109
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
1110
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
@@ -24,6 +23,7 @@
2423
import org.apache.http.impl.nio.client.HttpAsyncClients;
2524
import org.apache.http.message.BasicHeader;
2625
import org.apache.http.nio.client.HttpAsyncClient;
26+
import org.junit.jupiter.api.AfterAll;
2727
import org.junit.jupiter.api.BeforeAll;
2828
import org.junit.jupiter.api.Nested;
2929
import org.junit.jupiter.api.TestInstance;
@@ -35,8 +35,6 @@ class ApacheHttpAsyncClientTest {
3535
@RegisterExtension
3636
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent();
3737

38-
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
39-
4038
private final RequestConfig requestConfig =
4139
RequestConfig.custom()
4240
.setConnectTimeout((int) AbstractHttpClientTest.CONNECTION_TIMEOUT.toMillis())
@@ -54,12 +52,16 @@ class ApacheHttpAsyncClientTest {
5452

5553
@BeforeAll
5654
void setUp() {
57-
cleanup.deferAfterAll(client);
58-
cleanup.deferAfterAll(clientWithReadTimeout);
5955
client.start();
6056
clientWithReadTimeout.start();
6157
}
6258

59+
@AfterAll
60+
void tearDown() throws IOException {
61+
client.close();
62+
clientWithReadTimeout.close();
63+
}
64+
6365
HttpAsyncClient getClient(URI uri) {
6466
if (uri.toString().contains("/read-timeout")) {
6567
return clientWithReadTimeout;

0 commit comments

Comments
 (0)