Skip to content

Commit d6d218d

Browse files
committed
Fix MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException
Fixes issue #105422 On MacOS, FreeBSD, SunOS (the ports that share ProcessBSD.c) the get/set WorkingSet methods only work on the current process. Skip the parts of tests that operate on other processes. Remove now redundant MacOS-speicifc tests.
1 parent 4072e73 commit d6d218d

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ private static IntPtr ProcessorAffinityCore
5757
/// </summary>
5858
private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorkingSet)
5959
{
60+
EnsureState(State.HaveNonExitedId);
61+
6062
// We can only do this for the current process on OS X
6163
if (_processId != Environment.ProcessId)
6264
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);
@@ -86,6 +88,8 @@ private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorking
8688
/// <param name="resultingMax">The resulting maximum working set limit after any changes applied.</param>
8789
private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
8890
{
91+
EnsureState(State.HaveNonExitedId);
92+
8993
// We can only do this for the current process on OS X
9094
if (_processId != Environment.ProcessId)
9195
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,12 @@ public void TestMaxWorkingSet()
602602
}
603603

604604
[Fact]
605-
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
605+
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on iOS, MacCatalyst, and tvOS.")]
606606
public void MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
607607
{
608608
var process = new Process();
609609
Assert.Throws<InvalidOperationException>(() => process.MaxWorkingSet);
610-
}
611-
612-
[Fact]
613-
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
614-
public void MaxValueWorkingSet_GetSetMacos_ThrowsPlatformSupportedException()
615-
{
616-
var process = new Process();
617-
Assert.Throws<PlatformNotSupportedException>(() => process.MaxWorkingSet);
618-
Assert.Throws<PlatformNotSupportedException>(() => process.MaxWorkingSet = (IntPtr)1);
610+
Assert.Throws<InvalidOperationException>(() => process.MaxWorkingSet = (IntPtr)1);
619611
}
620612

621613
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
@@ -657,21 +649,13 @@ public void TestMinWorkingSet()
657649
}
658650

659651
[Fact]
660-
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
652+
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on iOS, MacCatalyst, and tvOS.")]
661653
public void MinWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
662654
{
663655
var process = new Process();
664656
Assert.Throws<InvalidOperationException>(() => process.MinWorkingSet);
665657
}
666658

667-
[Fact]
668-
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
669-
public void MinWorkingSet_GetMacos_ThrowsPlatformSupportedException()
670-
{
671-
var process = new Process();
672-
Assert.Throws<PlatformNotSupportedException>(() => process.MinWorkingSet);
673-
}
674-
675659
[Fact]
676660
public void TestModules()
677661
{

0 commit comments

Comments
 (0)