33
44import static java .util .concurrent .TimeUnit .MILLISECONDS ;
55import static org .assertj .core .api .Assertions .assertThat ;
6- import static org .awaitility .Awaitility .await ;
7- import static org .junit .jupiter .api .parallel .ExecutionMode .SAME_THREAD ;
6+ import static org .awaitility .Awaitility .waitAtMost ;
87
98import com .microsoft .applicationinsights .agent .bootstrap .MicrometerUtil ;
109import io .micrometer .core .instrument .Clock ;
2625import java .util .stream .Collectors ;
2726import org .junit .jupiter .api .Disabled ;
2827import org .junit .jupiter .api .Test ;
29- import org .junit .jupiter .api .parallel .Execution ;
3028
31- @ Execution (SAME_THREAD )
3229class MicrometerTest {
3330
3431 private static final AgentTestingMicrometerDelegate delegate = new AgentTestingMicrometerDelegate ();
@@ -64,7 +61,7 @@ void shouldCaptureTimeGauge() {
6461 TimeGauge .builder ("test-time-gauge" , "" , MILLISECONDS , obj -> 11.0 ).register (registry );
6562
6663 // then
67- await ( ).until (() -> getLastMeasurement ("test-time-gauge" ) != null );
64+ waitAtMost ( Duration . ofSeconds ( 20 ) ).until (() -> getLastMeasurement ("test-time-gauge" ) != null );
6865
6966 AgentTestingMicrometerDelegate .Measurement measurement = getLastMeasurement ("test-time-gauge" );
7067 assertThat (measurement .value ).isEqualTo (11 );
@@ -83,7 +80,7 @@ void shouldCaptureGauge() {
8380 Gauge .builder ("test-gauge" , () -> 22.0 ).register (registry );
8481
8582 // then
86- await ( ).until (() -> getLastMeasurement ("test-gauge" ) != null );
83+ waitAtMost ( Duration . ofSeconds ( 20 ) ).until (() -> getLastMeasurement ("test-gauge" ) != null );
8784
8885 AgentTestingMicrometerDelegate .Measurement measurement = getLastMeasurement ("test-gauge" );
8986 assertThat (measurement .value ).isEqualTo (22 );
@@ -104,7 +101,7 @@ void shouldCaptureCounter() {
104101 counter .increment (3.3 );
105102
106103 // then
107- await ( ).until (() -> getLastMeasurement ("test-counter" ) != null );
104+ waitAtMost ( Duration . ofSeconds ( 20 ) ).until (() -> getLastMeasurement ("test-counter" ) != null );
108105
109106 AgentTestingMicrometerDelegate .Measurement measurement = getLastMeasurement ("test-counter" );
110107 assertThat (measurement .value ).isEqualTo (3.3 );
@@ -125,7 +122,7 @@ void shouldCaptureTimer() {
125122 timer .record (Duration .ofMillis (55 ));
126123
127124 // then
128- await ( ).until (() -> getLastMeasurement ("test-timer" ) != null );
125+ waitAtMost ( Duration . ofSeconds ( 20 ) ).until (() -> getLastMeasurement ("test-timer" ) != null );
129126
130127 AgentTestingMicrometerDelegate .Measurement measurement = getLastMeasurement ("test-timer" );
131128 assertThat (measurement .value ).isEqualTo (99 );
@@ -148,7 +145,7 @@ void shouldCaptureDistributionSummary() {
148145 distributionSummary .record (5.5 );
149146
150147 // then
151- await ( ).until (() -> getLastMeasurement ("test-summary" ) != null );
148+ waitAtMost ( Duration . ofSeconds ( 20 ) ).until (() -> getLastMeasurement ("test-summary" ) != null );
152149
153150 AgentTestingMicrometerDelegate .Measurement measurement = getLastMeasurement ("test-summary" );
154151 assertThat (measurement .value ).isEqualTo (9.9 );
@@ -191,7 +188,7 @@ void shouldCaptureLongTaskTimer() {
191188 });
192189
193190 // then
194- await ( ).untilAsserted (() -> {
191+ waitAtMost ( Duration . ofSeconds ( 20 ) ).untilAsserted (() -> {
195192 AgentTestingMicrometerDelegate .Measurement activeMeasurement =
196193 getLastMeasurement ("test-long-task-timer_active" );
197194 assertThat (activeMeasurement .value ).isEqualTo (2 );
@@ -223,7 +220,7 @@ void shouldCaptureFunctionCounter() {
223220 FunctionCounter .builder ("test-function-counter" , "" , obj -> 6.6 ).register (registry );
224221
225222 // then
226- await ( ).until (() -> getLastMeasurement ("test-function-counter" ) != null );
223+ waitAtMost ( Duration . ofSeconds ( 20 ) ).until (() -> getLastMeasurement ("test-function-counter" ) != null );
227224
228225 AgentTestingMicrometerDelegate .Measurement measurements =
229226 getLastMeasurement ("test-function-counter" );
@@ -244,7 +241,7 @@ void shouldCaptureFunctionTimer() {
244241 .register (registry );
245242
246243 // then
247- await ( ).until (() -> getLastMeasurement ("test-function-timer" ) != null );
244+ waitAtMost ( Duration . ofSeconds ( 20 ) ).until (() -> getLastMeasurement ("test-function-timer" ) != null );
248245
249246 AgentTestingMicrometerDelegate .Measurement measurement =
250247 getLastMeasurement ("test-function-timer" );
0 commit comments