jmx-dev RFR: 8354407: Test com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java still fails on Windows [v2]

Leonid Mesnik lmesnik at openjdk.org
Wed Apr 30 21:02:04 UTC 2025


On Wed, 30 Apr 2025 18:33:31 GMT, Kevin Walls <kevinw at openjdk.org> wrote:

>> test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java line 60:
>> 
>>> 58:                 // A good reading: forget any previous -1.
>>> 59:                 ex = null;
>>> 60:                 good++;
>> 
>> The `ex = null` is a little misleading because actually it's irrelevant. An error on the next iteration will set it again, but it will be ignored because `good != 0`.
>
> Yes, as long as there is a good value captured, Windows should pass.
> We could get into how many good values we should see, I might suggest 6 out of 10? But that seems like a guessing game.
> The breakage in this feature before meant it could never return a good value, that's what we need to guard against.

I would simplify to 

 for (int i = 0; i < TEST_COUNT; i++) {
            double load = mbean.getProcessCpuLoad();
            if (load == -1.0 && Platform.isWindows()) {
                // Some Windows 2019 systems can return -1 for the first few reads.
                // Remember a -1 in case it never gets better.
                // Some Windows systems can return -1 occasionally, at any time.
                // Will fail if we never see good values.
               
            } else if (load < 0.0 || load > 1.0) {
                throw new RuntimeException("getProcessCpuLoad() returns " + load
                          + " which is not in the [0.0,1.0] interval");
            } else { 
               // we got at least one load from 0.0 to 1.0, that's good to pass on Wiindows
                good++;
          }
            try {
                Thread.sleep(200);

            }
        }

    
        if (good == 0 && Platform.isWindows()) {
            // Never get any good results on Windows 2019
            throw throw new RuntimeException("getProcessCpuLoad() returns  always -1.0 on Windows in 10 attempts. ");
        }
    }

does it makes a sense?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24961#discussion_r2069432691


More information about the jmx-dev mailing list