Skip to content

Commit 09cae5f

Browse files
committed
8354407: Test com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java still fails on Windows
Reviewed-by: cjplummer, lmesnik
1 parent 2ad639f commit 09cae5f

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@
3434
import jdk.test.lib.Platform;
3535

3636
public class GetProcessCpuLoad {
37+
38+
private static final int TEST_COUNT = 10;
39+
3740
public static void main(String[] argv) throws Exception {
3841
OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean)
3942
ManagementFactory.getOperatingSystemMXBean();
4043

4144
Exception ex = null;
42-
double load;
45+
int good = 0;
4346

44-
for(int i = 0; i < 10; i++) {
45-
load = mbean.getProcessCpuLoad();
47+
for (int i = 0; i < TEST_COUNT; i++) {
48+
double load = mbean.getProcessCpuLoad();
4649
if (load == -1.0 && Platform.isWindows()) {
47-
// Some Windows 2019 systems can return -1 for the first few reads.
48-
// Remember a -1 in case it never gets better.
50+
// Some Windows systems can return -1 occasionally, at any time.
51+
// Will fail if we never see good values.
4952
ex = new RuntimeException("getProcessCpuLoad() returns " + load
5053
+ " which is not in the [0.0,1.0] interval");
5154
} else if (load < 0.0 || load > 1.0) {
@@ -54,6 +57,7 @@ public static void main(String[] argv) throws Exception {
5457
} else {
5558
// A good reading: forget any previous -1.
5659
ex = null;
60+
good++;
5761
}
5862
try {
5963
Thread.sleep(200);
@@ -62,7 +66,8 @@ public static void main(String[] argv) throws Exception {
6266
}
6367
}
6468

65-
if (ex != null) {
69+
if (good == 0) {
70+
// Delayed failure for Windows.
6671
throw ex;
6772
}
6873
}

test/jdk/com/sun/management/OperatingSystemMXBean/TEST.properties

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)