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

Kevin Walls kevinw at openjdk.org
Wed Apr 30 21:22:45 UTC 2025


On Wed, 30 Apr 2025 20:59:23 GMT, Leonid Mesnik <lmesnik at openjdk.org> wrote:

>> 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?

Thanks Leonid, yes we could do it like that.  There have to be a load of ways we could arrange this.  Yes, it could be a little simpler that what we have now, although it's not _that_ complicated now...

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

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


More information about the jmx-dev mailing list