Skip to content

Commit

Permalink
Fix flakiness in DynatraceMeterRegistryTest.shouldTrackPercentilesWhe…
Browse files Browse the repository at this point in the history
…nDynatraceSummaryInstrumentsNotUsed()

Signed-off-by: Johnny Lim <[email protected]>
  • Loading branch information
izeye committed Feb 6, 2025
1 parent 20d0a9e commit a56dad6
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,23 @@ void shouldTrackPercentilesWhenDynatraceSummaryInstrumentsNotUsed() throws Throw
DistributionSummary distributionSummary = DistributionSummary.builder("my.ds")
.publishPercentiles(trackedPercentiles)
.register(registry);
CountDownLatch lttCountDownLatch = new CountDownLatch(1);
LongTaskTimer longTaskTimer = LongTaskTimer.builder("my.ltt")
.publishPercentiles(trackedPercentiles)
.register(registry);

timer.record(Duration.ofMillis(100));
distributionSummary.record(100);

CountDownLatch lttCountDownLatch1 = new CountDownLatch(1);
CountDownLatch lttCountDownLatch2 = new CountDownLatch(1);

ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> longTaskTimer.record(() -> {
clock.add(Duration.ofMillis(100));
lttCountDownLatch1.countDown();

try {
assertThat(lttCountDownLatch.await(300, MILLISECONDS)).isTrue();
assertThat(lttCountDownLatch2.await(300, MILLISECONDS)).isTrue();
}
catch (InterruptedException e) {
throw new RuntimeException(e);
Expand All @@ -193,9 +196,10 @@ void shouldTrackPercentilesWhenDynatraceSummaryInstrumentsNotUsed() throws Throw

clock.add(dynatraceConfig.step());

assertThat(lttCountDownLatch1.await(100, MILLISECONDS)).isTrue();
registry.publish();
// release long task timer
lttCountDownLatch.countDown();
lttCountDownLatch2.countDown();

verify(httpClient).send(
assertArg((request -> assertThat(request.getEntity()).asString()
Expand Down

0 comments on commit a56dad6

Please sign in to comment.