Skip to content

Commit

Permalink
Fix flakiness in JettyClientMetricsWithObservationTest.activeTimer() (#…
Browse files Browse the repository at this point in the history
…5894)

Signed-off-by: Johnny Lim <[email protected]>
  • Loading branch information
izeye authored Feb 6, 2025
1 parent fd6d438 commit 20d0a9e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions micrometer-jetty12/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
testImplementation project(":micrometer-test")

testImplementation libs.httpcomponents.client
testImplementation 'org.awaitility:awaitility'
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
package io.micrometer.jetty12.client;

import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import io.micrometer.core.instrument.LongTaskTimer;
import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler;
import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.tck.TestObservationRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Duration;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

class JettyClientMetricsWithObservationTest extends JettyClientMetricsTest {

Expand All @@ -47,13 +51,31 @@ protected void addInstrumentingListener() {

@Test
void activeTimer(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
stubFor(get("/ok").willReturn(ok()));
stubFor(get("/ok").willReturn(ok().withFixedDelay(100)));

Thread thread = new Thread(() -> {
try {
httpClient.GET("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/ok");
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
});
thread.start();

await().atMost(Duration.ofMillis(100))
.pollDelay(Duration.ofMillis(10))
.pollInterval(Duration.ofMillis(10))
.untilAsserted(() -> {
LongTaskTimer longTaskTimer = registry.find("jetty.client.requests.active")
.tags("uri", "/ok", "method", "GET")
.longTaskTimer();
assertThat(longTaskTimer).isNotNull();
assertThat(longTaskTimer.activeTasks()).isOne();
});

thread.join();

httpClient.GET("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/ok");
assertThat(registry.get("jetty.client.requests.active")
.tags("uri", "/ok", "method", "GET")
.longTaskTimer()
.activeTasks()).isOne();
httpClient.stop();

assertThat(singleRequestLatch.await(10, SECONDS)).isTrue();
Expand Down

0 comments on commit 20d0a9e

Please sign in to comment.