Skip to content

Commit 72a4b26

Browse files
lewingtmds
andauthored
ProcessTests: allow WorkingSet to be zero just after launching the process. (#85649) (#93572)
* 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. Co-authored-by: Tom Deseyn <tom.deseyn@gmail.com>
1 parent 19045fa commit 72a4b26

File tree

1 file changed

+78
-4
lines changed

1 file changed

+78
-4
lines changed

src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,25 @@ public void TestPeakWorkingSet64()
766766
{
767767
CreateDefaultProcess();
768768

769-
AssertNonZeroAllZeroDarwin(_process.PeakWorkingSet64);
769+
if (OperatingSystem.IsMacOS())
770+
{
771+
Assert.Equal(0, _process.PeakWorkingSet64);
772+
return;
773+
}
774+
775+
// On recent Linux kernels (6.2+) working set can be zero just after the process started.
776+
ExecuteWithRetryOnLinux(() =>
777+
{
778+
try
779+
{
780+
Assert.NotEqual(0, _process.PeakWorkingSet64);
781+
}
782+
catch
783+
{
784+
_process.Refresh();
785+
throw;
786+
}
787+
});
770788
}
771789

772790
[Fact]
@@ -819,7 +837,19 @@ public void TestWorkingSet64()
819837
return;
820838
}
821839

822-
Assert.InRange(_process.WorkingSet64, 1, long.MaxValue);
840+
// On recent Linux kernels (6.2+) working set can be zero just after the process started.
841+
ExecuteWithRetryOnLinux(() =>
842+
{
843+
try
844+
{
845+
Assert.InRange(_process.WorkingSet64, 1, long.MaxValue);
846+
}
847+
catch
848+
{
849+
_process.Refresh();
850+
throw;
851+
}
852+
});
823853
}
824854

825855
[Fact]
@@ -2011,9 +2041,29 @@ public void TestPeakWorkingSet()
20112041
{
20122042
CreateDefaultProcess();
20132043

2044+
if (OperatingSystem.IsMacOS())
2045+
{
20142046
#pragma warning disable 0618
2015-
AssertNonZeroAllZeroDarwin(_process.PeakWorkingSet);
2047+
Assert.Equal(0, _process.PeakWorkingSet);
20162048
#pragma warning restore 0618
2049+
return;
2050+
}
2051+
2052+
// On recent Linux kernels (6.2+) working set can be zero just after the process started.
2053+
ExecuteWithRetryOnLinux(() =>
2054+
{
2055+
try
2056+
{
2057+
#pragma warning disable 0618
2058+
Assert.NotEqual(0, _process.PeakWorkingSet);
2059+
#pragma warning restore 0618
2060+
}
2061+
catch
2062+
{
2063+
_process.Refresh();
2064+
throw;
2065+
}
2066+
});
20172067
}
20182068

20192069
[Fact]
@@ -2077,9 +2127,21 @@ public void TestWorkingSet()
20772127
return;
20782128
}
20792129

2130+
// On recent Linux kernels (6.2+) working set can be zero just after the process started.
2131+
ExecuteWithRetryOnLinux(() =>
2132+
{
2133+
try
2134+
{
20802135
#pragma warning disable 0618
2081-
Assert.InRange(_process.WorkingSet, 1, int.MaxValue);
2136+
Assert.InRange(_process.WorkingSet, 1, int.MaxValue);
20822137
#pragma warning restore 0618
2138+
}
2139+
catch
2140+
{
2141+
_process.Refresh();
2142+
throw;
2143+
}
2144+
});
20832145
}
20842146

20852147
[Fact]
@@ -2673,5 +2735,17 @@ private SecureString AsSecureString(string str)
26732735

26742736
return secureString;
26752737
}
2738+
2739+
private static void ExecuteWithRetryOnLinux(Action test)
2740+
{
2741+
if (OperatingSystem.IsLinux())
2742+
{
2743+
RetryHelper.Execute(test, retryWhen: ex => ex is XunitException);
2744+
}
2745+
else
2746+
{
2747+
test();
2748+
}
2749+
}
26762750
}
26772751
}

0 commit comments

Comments
 (0)