1616package io .micrometer .jetty12 .client ;
1717
1818import com .github .tomakehurst .wiremock .junit5 .WireMockRuntimeInfo ;
19+ import io .micrometer .core .instrument .LongTaskTimer ;
1920import io .micrometer .core .instrument .observation .DefaultMeterObservationHandler ;
2021import io .micrometer .observation .ObservationRegistry ;
2122import io .micrometer .observation .tck .TestObservationRegistry ;
2223import org .junit .jupiter .api .BeforeEach ;
2324import org .junit .jupiter .api .Test ;
2425
26+ import java .time .Duration ;
27+
2528import static com .github .tomakehurst .wiremock .client .WireMock .*;
2629import static java .util .concurrent .TimeUnit .SECONDS ;
2730import static org .assertj .core .api .Assertions .assertThat ;
31+ import static org .awaitility .Awaitility .await ;
2832
2933class JettyClientMetricsWithObservationTest extends JettyClientMetricsTest {
3034
@@ -47,13 +51,31 @@ protected void addInstrumentingListener() {
4751
4852 @ Test
4953 void activeTimer (WireMockRuntimeInfo wmRuntimeInfo ) throws Exception {
50- stubFor (get ("/ok" ).willReturn (ok ()));
54+ stubFor (get ("/ok" ).willReturn (ok ().withFixedDelay (100 )));
55+
56+ Thread thread = new Thread (() -> {
57+ try {
58+ httpClient .GET ("http://localhost:" + wmRuntimeInfo .getHttpPort () + "/ok" );
59+ }
60+ catch (Exception ex ) {
61+ throw new RuntimeException (ex );
62+ }
63+ });
64+ thread .start ();
65+
66+ await ().atMost (Duration .ofMillis (100 ))
67+ .pollDelay (Duration .ofMillis (10 ))
68+ .pollInterval (Duration .ofMillis (10 ))
69+ .untilAsserted (() -> {
70+ LongTaskTimer longTaskTimer = registry .find ("jetty.client.requests.active" )
71+ .tags ("uri" , "/ok" , "method" , "GET" )
72+ .longTaskTimer ();
73+ assertThat (longTaskTimer ).isNotNull ();
74+ assertThat (longTaskTimer .activeTasks ()).isOne ();
75+ });
76+
77+ thread .join ();
5178
52- httpClient .GET ("http://localhost:" + wmRuntimeInfo .getHttpPort () + "/ok" );
53- assertThat (registry .get ("jetty.client.requests.active" )
54- .tags ("uri" , "/ok" , "method" , "GET" )
55- .longTaskTimer ()
56- .activeTasks ()).isOne ();
5779 httpClient .stop ();
5880
5981 assertThat (singleRequestLatch .await (10 , SECONDS )).isTrue ();
0 commit comments