Skip to content

Commit

Permalink
Fix CPU usage tests on mobile platforms (#105722)
Browse files Browse the repository at this point in the history
* Fix CpuUsage Tests on mobile platforms

* Remove empty line
  • Loading branch information
tarekgh committed Jul 30, 2024
1 parent 9d8f54a commit 9653506
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,20 @@ public void TestCpuUsage()
{
if ((OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) || PlatformDetection.IstvOS || PlatformDetection.IsBrowser)
{
// Environment should return 0 for all values
Environment.ProcessCpuUsage usage = Environment.CpuUsage;
Assert.Equal(TimeSpan.Zero, usage.UserTime);
Assert.Equal(TimeSpan.Zero, usage.PrivilegedTime);
Assert.Equal(TimeSpan.Zero, usage.TotalTime);

if (usage.UserTime == TimeSpan.Zero)
{
// Environment should return 0 for all values
Assert.Equal(TimeSpan.Zero, usage.PrivilegedTime);
Assert.Equal(TimeSpan.Zero, usage.TotalTime);
}
else
{
// Mobile platforms emulators may return non-zero values
Assert.NotEqual(TimeSpan.Zero, usage.PrivilegedTime);
Assert.Equal(usage.TotalTime, usage.UserTime + usage.PrivilegedTime);
}
}
else
{
Expand Down

0 comments on commit 9653506

Please sign in to comment.