Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Do not use retry to fix the test; stats are approximate; just check for existence, not values #5112

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions metrics/metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@
<artifactId>helidon-webclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
38 changes: 3 additions & 35 deletions metrics/metrics/src/test/java/io/helidon/metrics/TestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import io.helidon.common.http.Http;
import io.helidon.common.http.MediaType;
import io.helidon.config.testing.MatcherWithRetry;
import io.helidon.media.jsonp.JsonpSupport;
import io.helidon.webclient.WebClient;
import io.helidon.webclient.WebClientRequestBuilder;
Expand All @@ -54,7 +53,6 @@
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.not;

public class TestServer {
Expand Down Expand Up @@ -193,6 +191,9 @@ void checkMetricsForExecutorService() throws Exception {
String jsonKeyForCompleteTaskCountInThreadPool =
"executor-service.completed-task-count;poolIndex=0;supplierCategory=my-thread-thread-pool-1;supplierIndex=0";

// Because ThreadPoolExecutor methods are documented as reporting approximations of task counts, etc., we should
// not depend on the values changing in a reasonable time period...or at all. So this test simply makes sure that
// an expected metric is present.
WebClientRequestBuilder metricsRequestBuilder = webClientBuilder
.build()
.get()
Expand All @@ -210,39 +211,6 @@ void checkMetricsForExecutorService() throws Exception {
assertThat("JSON metrics results before accessing slow endpoint",
metrics,
hasKey(jsonKeyForCompleteTaskCountInThreadPool));

int completedTaskCount = metrics.getInt(jsonKeyForCompleteTaskCountInThreadPool);
assertThat("Completed task count before accessing slow endpoint", completedTaskCount, is(0));

WebClientResponse slowGreetResponse = webClientBuilder
.build()
.get()
.accept(MediaType.TEXT_PLAIN)
.path("greet/slow")
.submit()
.await(CLIENT_TIMEOUT);

assertThat("Slow greet access response status", slowGreetResponse.status().code(), is(200));

MatcherWithRetry.retry(() -> {

WebClientResponse secondMetricsResponse = metricsRequestBuilder
.submit()
.await(CLIENT_TIMEOUT);

assertThat("Second access to metrics", secondMetricsResponse.status().code(), is(200));

JsonObject secondMetrics = secondMetricsResponse.content().as(JsonObject.class).await(CLIENT_TIMEOUT);

assertThat("JSON metrics results after accessing slow endpoint",
secondMetrics,
hasKey(jsonKeyForCompleteTaskCountInThreadPool));

int secondCompletedTaskCount = secondMetrics.getInt(jsonKeyForCompleteTaskCountInThreadPool);

assertThat("Completed task count after accessing slow endpoint", secondCompletedTaskCount, is(1));
return true;
});
}

@ParameterizedTest
Expand Down