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

Kevin Walls kevinw at openjdk.org
Thu May 1 10:09:44 UTC 2025


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

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

I do like having the Exception created at the point where we recognise there's a problem.  While the message could hard-code in the -1 in the Windows case, it must be also good to use the same expression to build the message, right next to each other.
I also like keeping the existing Exception wording, there isn't a real need to change it.
It's still a tiny little test routine and on future failure on Windows, it should be clear that we didn't receive any good values.
On balance would you be OK if we leave as it stands?

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

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


More information about the jmx-dev mailing list