浏览代码

Read response body in jax-rs client and google http client tests (#5672)

* Read response body in jax-rs client and google http client tests

* Apply suggestions from code review

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Lauri Tulmin 3 年之前
父节点
当前提交
ce71fcca4d

+ 4 - 1
instrumentation/google-http-client-1.19/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/AbstractGoogleHttpClientTest.java

@@ -73,7 +73,10 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
   @Override
   protected final int sendRequest(
       HttpRequest request, String method, URI uri, Map<String, String> headers) throws Exception {
-    return sendRequest(request).getStatusCode();
+    HttpResponse response = sendRequest(request);
+    // read request body to avoid broken pipe errors on the server side
+    response.parseAsString();
+    return response.getStatusCode();
   }
 
   protected abstract HttpResponse sendRequest(HttpRequest request) throws Exception;

+ 4 - 0
instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy

@@ -44,6 +44,8 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
     try {
       def body = BODY_METHODS.contains(method) ? Entity.text("") : null
       def response = request.build(method, body).invoke()
+      // read response body to avoid broken pipe errors on the server side
+      response.readEntity(String)
       try {
         response.close()
       } catch (IOException ignore) {
@@ -61,6 +63,8 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
     request.async().method(method, (Entity) body, new InvocationCallback<Response>() {
       @Override
       void completed(Response response) {
+        // read response body
+        response.readEntity(String)
         requestResult.complete(response.status)
       }