Skip to content

Commit c7ed10a

Browse files
authored
Work around flaky java http client http/2 tests (#13958)
1 parent 4a243ca commit c7ed10a

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

instrumentation/java-http-client/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/javahttpclient/JavaHttpClientTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
1212
import java.net.http.HttpClient;
1313
import org.junit.jupiter.api.Nested;
14-
import org.junit.jupiter.api.condition.DisabledForJreRange;
15-
import org.junit.jupiter.api.condition.JRE;
1614
import org.junit.jupiter.api.extension.RegisterExtension;
1715

1816
public abstract class JavaHttpClientTest extends AbstractJavaHttpClientTest {
@@ -34,7 +32,6 @@ protected void configureHttpClientBuilder(HttpClient.Builder httpClientBuilder)
3432
}
3533
}
3634

37-
@DisabledForJreRange(min = JRE.JAVA_25) // flaky on jdk25-ea
3835
@Nested
3936
static class Http2ClientTest extends JavaHttpClientTest {
4037

instrumentation/java-http-client/library/src/test/java/io/opentelemetry/instrumentation/javahttpclient/JavaHttpClientTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import java.net.http.HttpClient;
1313
import java.util.Collections;
1414
import org.junit.jupiter.api.Nested;
15-
import org.junit.jupiter.api.condition.DisabledForJreRange;
16-
import org.junit.jupiter.api.condition.JRE;
1715
import org.junit.jupiter.api.extension.RegisterExtension;
1816

1917
public abstract class JavaHttpClientTest extends AbstractJavaHttpClientTest {
@@ -41,7 +39,6 @@ protected void configureHttpClientBuilder(HttpClient.Builder httpClientBuilder)
4139
}
4240
}
4341

44-
@DisabledForJreRange(min = JRE.JAVA_25) // flaky on jdk25-ea
4542
@Nested
4643
static class Http2ClientTest extends JavaHttpClientTest {
4744

instrumentation/java-http-client/testing/src/main/java/io/opentelemetry/instrumentation/javahttpclient/AbstractJavaHttpClientTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public HttpRequest buildRequest(String method, URI uri, Map<String, String> head
4545
HttpRequest.Builder requestBuilder =
4646
HttpRequest.newBuilder().uri(uri).method(method, HttpRequest.BodyPublishers.noBody());
4747
headers.forEach(requestBuilder::header);
48+
if (client.version() == HttpClient.Version.HTTP_2) {
49+
// notify HttpClientTestServer that the request comes from java http client using http/2 so
50+
// that the server can work around http/2 tests failing with java.io.IOException: RST_STREAM
51+
// received
52+
requestBuilder.header("java-http-client-http2", "true");
53+
}
4854
if (uri.toString().contains("/read-timeout")) {
4955
requestBuilder.timeout(READ_TIMEOUT);
5056
}

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestServer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ protected void configure(ServerBuilder sb) throws Exception {
147147
}
148148
span.startSpan().end();
149149

150-
return delegate.serve(ctx, req);
150+
// this header is set by java http client http/2 tests
151+
// we delay the response a bit to ensure that client can send the full request before
152+
// it receives the response
153+
// this is a workaround for http/2 tests failing with java.io.IOException: RST_STREAM
154+
// received
155+
boolean delay = req.headers().get("java-http-client-http2") != null;
156+
157+
HttpResponse response = delegate.serve(ctx, req);
158+
return delay ? HttpResponse.delayed(response, Duration.ofMillis(10)) : response;
151159
})
152160
.decorator(LoggingService.newDecorator());
153161
}

0 commit comments

Comments
 (0)