Skip to content

Commit

Permalink
test: drain HttpResponse in tests (5852)
Browse files Browse the repository at this point in the history
Drain `HttpResponse` in tests

Motivation:

In Armeria CI, we saw Netty leak reports from kubernetes-client CI tests.
After investigating, I found out that some of the tests did not
consume `HttpResponse`. As a result, some `ByteBuf`s were not
subscribed to and remained in the Publisher's internal buffer.

Modifications:

- Fixed to call `AsyncBody.consume()` where it was not called before.

Result:

No more leaks in CI builds.
  • Loading branch information
manusa authored Apr 10, 2024
2 parents eca3f31 + 11c0bfe commit dd53202
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ public CompletableFuture<Boolean> afterFailure(BasicBuilder builder, HttpRespons
});
// When
try (HttpClient client = builder.build()) {
client.consumeBytes(
final HttpResponse<AsyncBody> asyncR = client.consumeBytes(
client.newHttpRequestBuilder().uri(server.url("/not-found")).build(),
(s, ab) -> ab.consume())
.get(10, TimeUnit.SECONDS);
asyncR.body().consume();
asyncR.body().done().get(10L, TimeUnit.SECONDS);
}
// Then
assertThat(interceptedResponses)
Expand Down Expand Up @@ -279,10 +281,12 @@ public void after(HttpRequest request, HttpResponse<?> response, Consumer<List<B
});
// When
try (HttpClient client = builder.build()) {
client.consumeBytes(
final HttpResponse<AsyncBody> asyncR = client.consumeBytes(
client.newHttpRequestBuilder().uri(server.url("/success")).build(),
(s, ab) -> ab.consume())
.get(10, TimeUnit.SECONDS);
asyncR.body().consume();
asyncR.body().done().get(10L, TimeUnit.SECONDS);
}
// Then
assertThat(responseFuture)
Expand All @@ -306,10 +310,12 @@ public void after(HttpRequest request, HttpResponse<?> response, Consumer<List<B
});
// When
try (HttpClient client = builder.build()) {
client.consumeBytes(
final HttpResponse<AsyncBody> asyncR = client.consumeBytes(
client.newHttpRequestBuilder().uri(server.url("/client-error")).build(),
(s, ab) -> ab.consume())
.get(10, TimeUnit.SECONDS);
asyncR.body().consume();
asyncR.body().done().get(10L, TimeUnit.SECONDS);
}
// Then
assertThat(responseFuture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public void http1Connections() throws Exception {
assertThat(asyncResponses)
.hasSize(MAX_HTTP_1_CONNECTIONS)
.extracting(CompletableFuture::join)
.extracting(HttpResponse::code).containsOnly(204);
.extracting(response -> {
response.body().consume();
return response.code();
})
.containsOnly(204);
}
}

Expand Down

0 comments on commit dd53202

Please sign in to comment.