Skip to content

Commit 53eec4e

Browse files
authored
Fix flakiness in DynatraceMeterRegistryTest.shouldTrackPercentilesWhenDynatraceSummaryInstrumentsNotUsed() (#6013)
Signed-off-by: Johnny Lim <[email protected]>
1 parent 42628cf commit 53eec4e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceMeterRegistryTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ class DynatraceMeterRegistryTest {
5353
void setUp() {
5454
this.config = createDefaultDynatraceConfig();
5555
this.clock = new MockClock();
56-
this.clock.add(System.currentTimeMillis(), MILLISECONDS); // Set the clock to
57-
// something recent so
58-
// that the Dynatrace
59-
// library will not
60-
// complain.
56+
// Set the clock to something recent so that the Dynatrace library will not
57+
// complain.
58+
this.clock.add(System.currentTimeMillis(), MILLISECONDS);
6159
this.httpClient = mock(HttpSender.class);
6260
this.meterRegistry = DynatraceMeterRegistry.builder(config).clock(clock).httpClient(httpClient).build();
6361
}
@@ -182,8 +180,9 @@ void shouldTrackPercentilesWhenDynatraceSummaryInstrumentsNotUsed() throws Throw
182180
CountDownLatch lttCountDownLatch2 = new CountDownLatch(1);
183181

184182
ExecutorService executorService = Executors.newSingleThreadExecutor();
183+
Duration longTaskTimerDuration = Duration.ofMillis(100);
185184
executorService.submit(() -> longTaskTimer.record(() -> {
186-
clock.add(Duration.ofMillis(100));
185+
clock.add(longTaskTimerDuration);
187186
lttCountDownLatch1.countDown();
188187

189188
try {
@@ -194,7 +193,10 @@ void shouldTrackPercentilesWhenDynatraceSummaryInstrumentsNotUsed() throws Throw
194193
}
195194
}));
196195

197-
clock.add(dynatraceConfig.step());
196+
// The 'longTaskTimerDuration' should be subtracted as depending on
197+
// System.currentTimeMillis(), the 'longTaskTimerDuration' could start another
198+
// step.
199+
clock.add(dynatraceConfig.step().minus(longTaskTimerDuration));
198200

199201
assertThat(lttCountDownLatch1.await(100, MILLISECONDS)).isTrue();
200202
registry.publish();

0 commit comments

Comments
 (0)