Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public void testTimer() throws InterruptedException {
try (Timer ignored = noLabels.startTimer()) {
Thread.sleep(12);
}
assertThat(getValue(noLabels))
.isCloseTo(0.012, offset(0.005)); // 5ms delta should be enough so this isn't flaky
assertThat(getValue(noLabels)).isGreaterThan(0.01);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ void testInvalidThreadIds() {
// Number of threads to create with invalid thread ids
int numberOfInvalidThreadIds = 2;

Map<String, Double> expected = getCountByState(registry.scrape());
expected.compute(
"UNKNOWN",
(key, oldValue) ->
oldValue == null ? numberOfInvalidThreadIds : oldValue + numberOfInvalidThreadIds);
Map<String, Double> before = getCountByState(registry.scrape());
double unknownBefore = before.getOrDefault("UNKNOWN", 0.0);

final CountDownLatch countDownLatch = new CountDownLatch(numberOfInvalidThreadIds);

Expand All @@ -132,12 +129,12 @@ void testInvalidThreadIds() {
new ThreadWithInvalidId(-i, new TestRunnable(countDownLatch)).start();
}

Map<String, Double> actual = getCountByState(registry.scrape());
Map<String, Double> after = getCountByState(registry.scrape());
double unknownAfter = after.getOrDefault("UNKNOWN", 0.0);

assertThat(actual).hasSameSizeAs(expected);
for (String threadState : expected.keySet()) {
assertThat(actual.get(threadState)).isEqualTo(expected.get(threadState));
}
// The UNKNOWN count should increase by exactly the number of invalid thread ids.
// Other states may change due to background threads, so we only assert on UNKNOWN.
assertThat(unknownAfter - unknownBefore).isEqualTo((double) numberOfInvalidThreadIds);
} finally {
for (int i = 0; i < numberOfInvalidThreadIds; i++) {
countDownLatch.countDown();
Expand Down
Loading