Skip to content

Commit

Permalink
ProcessTests: allow WorkingSet to be zero just after launching the pr…
Browse files Browse the repository at this point in the history
…ocess. (#85649)

* ProcessTests: allow WorkingSet to be zero just after launching the process.

The WorkingSet tests fail on Fedora 38+ because a zero working set value
is observed just after the process start.
  • Loading branch information
tmds committed May 17, 2023
1 parent 07819e9 commit 27d0009
Showing 1 changed file with 78 additions and 4 deletions.
82 changes: 78 additions & 4 deletions src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,25 @@ public void TestPeakWorkingSet64()
{
CreateDefaultProcess();

AssertNonZeroAllZeroDarwin(_process.PeakWorkingSet64);
if (OperatingSystem.IsMacOS())
{
Assert.Equal(0, _process.PeakWorkingSet64);
return;
}

// On recent Linux kernels (6.2+) working set can be zero just after the process started.
ExecuteWithRetryOnLinux(() =>
{
try
{
Assert.NotEqual(0, _process.PeakWorkingSet64);
}
catch
{
_process.Refresh();
throw;
}
});
}

[Fact]
Expand Down Expand Up @@ -822,7 +840,19 @@ public void TestWorkingSet64()
return;
}

Assert.InRange(_process.WorkingSet64, 1, long.MaxValue);
// On recent Linux kernels (6.2+) working set can be zero just after the process started.
ExecuteWithRetryOnLinux(() =>
{
try
{
Assert.InRange(_process.WorkingSet64, 1, long.MaxValue);
}
catch
{
_process.Refresh();
throw;
}
});
}

[Fact]
Expand Down Expand Up @@ -2014,9 +2044,29 @@ public void TestPeakWorkingSet()
{
CreateDefaultProcess();

if (OperatingSystem.IsMacOS())
{
#pragma warning disable 0618
AssertNonZeroAllZeroDarwin(_process.PeakWorkingSet);
Assert.Equal(0, _process.PeakWorkingSet);
#pragma warning restore 0618
return;
}

// On recent Linux kernels (6.2+) working set can be zero just after the process started.
ExecuteWithRetryOnLinux(() =>
{
try
{
#pragma warning disable 0618
Assert.NotEqual(0, _process.PeakWorkingSet);
#pragma warning restore 0618
}
catch
{
_process.Refresh();
throw;
}
});
}

[Fact]
Expand Down Expand Up @@ -2080,9 +2130,21 @@ public void TestWorkingSet()
return;
}

// On recent Linux kernels (6.2+) working set can be zero just after the process started.
ExecuteWithRetryOnLinux(() =>
{
try
{
#pragma warning disable 0618
Assert.InRange(_process.WorkingSet, 1, int.MaxValue);
Assert.InRange(_process.WorkingSet, 1, int.MaxValue);
#pragma warning restore 0618
}
catch
{
_process.Refresh();
throw;
}
});
}

[Fact]
Expand Down Expand Up @@ -2677,5 +2739,17 @@ private SecureString AsSecureString(string str)

return secureString;
}

private static void ExecuteWithRetryOnLinux(Action test)
{
if (OperatingSystem.IsLinux())
{
RetryHelper.Execute(test, retryWhen: ex => ex is XunitException);
}
else
{
test();
}
}
}
}

0 comments on commit 27d0009

Please sign in to comment.