Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tmds marked this conversation as resolved.
Show resolved Hide resolved
{
_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();
}
}
}
}