Skip to content

Commit e1148f0

Browse files
Merge branch '1.8.x' into 1.9.x
2 parents bc90fac + f589c9b commit e1148f0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/system/ProcessorMetricsTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import org.junit.jupiter.api.BeforeEach;
2121
import org.junit.jupiter.api.Test;
2222

23+
import java.time.Duration;
24+
2325
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
26+
import static org.awaitility.Awaitility.await;
2427
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2528

2629
/**
@@ -43,21 +46,21 @@ void setup() {
4346

4447
@Test
4548
void cpuMetrics() {
46-
assertThat(registry.get("system.cpu.count").gauge().value()).isGreaterThan(0);
49+
assertThat(registry.get("system.cpu.count").gauge().value()).isPositive();
4750
if (System.getProperty("os.name").toLowerCase().contains("win")) {
4851
assertThat(registry.find("system.load.average.1m").gauge()).describedAs("Not present on windows").isNull();
4952
}
5053
else {
51-
assertThat(registry.get("system.load.average.1m").gauge().value()).isGreaterThanOrEqualTo(0);
54+
assertThat(registry.get("system.load.average.1m").gauge().value()).isNotNegative();
5255
}
5356
}
5457

5558
@Test
5659
void hotspotCpuMetrics() {
5760
assumeTrue(!isOpenJ9());
5861

59-
assertThat(registry.get("system.cpu.usage").gauge().value()).isGreaterThanOrEqualTo(0);
60-
assertThat(registry.get("process.cpu.usage").gauge().value()).isGreaterThanOrEqualTo(0);
62+
assertThat(registry.get("system.cpu.usage").gauge().value()).isNotNegative();
63+
assertThat(registry.get("process.cpu.usage").gauge().value()).isNotNegative();
6164
}
6265

6366
@Test
@@ -69,11 +72,13 @@ void openJ9CpuMetrics() {
6972
* value - if supported - on subsequent calls. This holds true for
7073
* "system.cpu.usage" but not for "process.cpu.usage". The latter needs some
7174
* milliseconds of sleep before it actually returns a positive value on a
72-
* supported system. Thread.sleep() is flaky, though.
75+
* supported system.
7376
*/
7477
assertThat(registry.get("system.cpu.usage").gauge().value()).isGreaterThanOrEqualTo(-1);
75-
assertThat(registry.get("system.cpu.usage").gauge().value()).isGreaterThan(0);
78+
assertThat(registry.get("system.cpu.usage").gauge().value()).isPositive();
7679
assertThat(registry.get("process.cpu.usage").gauge().value()).isGreaterThanOrEqualTo(-1);
80+
await().atMost(Duration.ofMillis(200))
81+
.untilAsserted(() -> assertThat(registry.get("process.cpu.usage").gauge().value()).isPositive());
7782
}
7883

7984
private boolean isOpenJ9() {

0 commit comments

Comments
 (0)