45
45
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
46
46
47
47
import static org .assertj .core .api .Assertions .assertThat ;
48
+ import static org .awaitility .Awaitility .await ;
48
49
49
50
/**
50
51
* @author Soby Chacko
@@ -66,14 +67,16 @@ void verifyMetricsWithoutObservation(@Autowired MetricsListener listener,
66
67
template .send (METRICS_TEST_TOPIC , "test" ).get (10 , TimeUnit .SECONDS );
67
68
assertThat (listener .latch .await (10 , TimeUnit .SECONDS )).isTrue ();
68
69
69
- Timer timer = meterRegistry .find ("spring.kafka.listener" )
70
- .tags ("name" , "metricsTest-0" )
71
- .tag ("result" , "failure" )
72
- .timer ();
70
+ await ().untilAsserted (() -> {
71
+ Timer timer = meterRegistry .find ("spring.kafka.listener" )
72
+ .tags ("name" , "metricsTest-0" )
73
+ .tag ("result" , "failure" )
74
+ .timer ();
73
75
74
- assertThat (timer ).isNotNull ();
75
- assertThat (timer .getId ().getTag ("exception" ))
76
- .isEqualTo ("IllegalStateException" );
76
+ assertThat (timer ).isNotNull ();
77
+ assertThat (timer .getId ().getTag ("exception" ))
78
+ .isEqualTo ("IllegalStateException" );
79
+ });
77
80
}
78
81
79
82
@ Test
@@ -85,12 +88,14 @@ void verifyMetricsWithObservation(@Autowired ObservationListener observationList
85
88
template .send (METRICS_TEST_TOPIC , "test" ).get (10 , TimeUnit .SECONDS );
86
89
assertThat (observationListener .latch .await (10 , TimeUnit .SECONDS )).isTrue ();
87
90
88
- Timer timer = meterRegistry .find ("spring.kafka.listener" )
89
- .tag ("spring.kafka.listener.id" , "observationTest-0" )
90
- .tag ("error" , "IllegalStateException" )
91
- .timer ();
91
+ await ().untilAsserted (() -> {
92
+ Timer timer = meterRegistry .find ("spring.kafka.listener" )
93
+ .tag ("spring.kafka.listener.id" , "observationTest-0" )
94
+ .tag ("error" , "IllegalStateException" )
95
+ .timer ();
92
96
93
- assertThat (timer ).isNotNull ();
97
+ assertThat (timer ).isNotNull ();
98
+ });
94
99
}
95
100
96
101
@ Configuration
0 commit comments