Skip to content

Commit

Permalink
[3.x] Do not use retry to fix the test; stats are approximate; just c…
Browse files Browse the repository at this point in the history
…heck for existence, not values (#5112)

* Remove test of updated executor metrics; values from ThreadPoolExecutor are documented as approximations anyway

Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
tjquinno authored Oct 10, 2022
1 parent 42b3247 commit 5f4202e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
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

0 comments on commit 5f4202e

Please sign in to comment.