Skip to content

Commit

Permalink
Fix flakiness in Jersey3Test.helloResourceIsTimed() (#5920)
Browse files Browse the repository at this point in the history
Signed-off-by: Johnny Lim <[email protected]>
  • Loading branch information
izeye authored Feb 13, 2025
1 parent 6b530a9 commit 93e3803
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions samples/micrometer-samples-jersey3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ dependencies {
testImplementation libs.jersey3TestFrameworkJdkHttp
testImplementation libs.junitJupiter
testImplementation 'org.assertj:assertj-core'
testImplementation libs.awaitility
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import org.glassfish.jersey.test.JerseyTest;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

@SuppressWarnings("deprecation")
class Jersey3Test extends JerseyTest {
Expand All @@ -48,16 +50,18 @@ protected Application configure() {
}

@Test
void helloResourceIsTimed() throws InterruptedException {
void helloResourceIsTimed() {
String response = target("hello/Jersey").request().get(String.class);
assertThat(response).isEqualTo("Hello, Jersey");
// Jersey metrics are recorded asynchronously to the request completing
Thread.sleep(10);
Timer timer = registry.get(TIMER_METRIC_NAME)
.tags("method", "GET", "uri", "/hello/{name}", "status", "200", "exception", "None", "outcome", "SUCCESS")
.timer();
assertThat(timer.count()).isEqualTo(1);
assertThat(timer.totalTime(TimeUnit.NANOSECONDS)).isPositive();
await().atMost(Duration.ofSeconds(1)).untilAsserted(() -> {
Timer timer = registry.get(TIMER_METRIC_NAME)
.tags("method", "GET", "uri", "/hello/{name}", "status", "200", "exception", "None", "outcome",
"SUCCESS")
.timer();
assertThat(timer.count()).isEqualTo(1);
assertThat(timer.totalTime(TimeUnit.NANOSECONDS)).isPositive();
});
}

@Test
Expand Down

0 comments on commit 93e3803

Please sign in to comment.