Skip to content

Fix MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException#105424

Merged
stephentoub merged 1 commit into
dotnet:mainfrom
gwr:bsd-ws-limits
May 29, 2025
Merged

Fix MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException#105424
stephentoub merged 1 commit into
dotnet:mainfrom
gwr:bsd-ws-limits

Conversation

@gwr

@gwr gwr commented Jul 24, 2024

Copy link
Copy Markdown
Contributor

Fixes #105422

@stephentoub stephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@stephentoub

Copy link
Copy Markdown
Member

These tests needs to be addressed:

[Fact]
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
public void MinWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
Assert.Throws<InvalidOperationException>(() => process.MinWorkingSet);
}
[Fact]
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
public void MinWorkingSet_GetMacos_ThrowsPlatformSupportedException()
{
var process = new Process();
Assert.Throws<PlatformNotSupportedException>(() => process.MinWorkingSet);
}

@stephentoub stephentoub self-requested a review July 25, 2024 04:20
@gwr

gwr commented Jul 25, 2024

Copy link
Copy Markdown
Contributor Author

These tests needs to be addressed:

[Fact]
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
public void MinWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
Assert.Throws<InvalidOperationException>(() => process.MinWorkingSet);
}
[Fact]
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
public void MinWorkingSet_GetMacos_ThrowsPlatformSupportedException()
{
var process = new Process();
Assert.Throws<PlatformNotSupportedException>(() => process.MinWorkingSet);
}

Yeah, the SkipOnPlatform line(s) probably need adjustment. I think these tests should now pass on FreeBSD and OSX.
Someone needs to find time to remove the OS "skip" for each of these and try the test with that fix.

@am11

am11 commented Jul 25, 2024

Copy link
Copy Markdown
Member

In CI, this test is failing on osx with your changes:

    System.Diagnostics.Tests.ProcessTests.MinWorkingSet_GetMacos_ThrowsPlatformSupportedException [FAIL]
      Assert.Throws() Failure: Exception type was not an exact match
      Expected: typeof(System.PlatformNotSupportedException)
      Actual:   typeof(System.InvalidOperationException)
      ---- System.InvalidOperationException : No process is associated with this object.
      Stack Trace:
        /_/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs(672,0): at System.Diagnostics.Tests.ProcessTests.MinWorkingSet_GetMacos_ThrowsPlatformSupportedException()
        
           at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
        /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(50,0): at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
        ----- Inner Stack Trace -----
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs(949,0): at System.Diagnostics.Process.EnsureState(State state)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs(961,0): at System.Diagnostics.Process.EnsureState(State state)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs(60,0): at System.Diagnostics.Process.GetWorkingSetLimits(IntPtr& minWorkingSet, IntPtr& maxWorkingSet)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs(1014,0): at System.Diagnostics.Process.EnsureWorkingSetLimits()
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs(295,0): at System.Diagnostics.Process.get_MinWorkingSet()
        /_/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs(672,0): at System.Diagnostics.Tests.ProcessTests.<>c__DisplayClass40_0.<MinWorkingSet_GetMacos_ThrowsPlatformSupportedException>b__0()
    System.Diagnostics.Tests.ProcessTests.TestProcessRecycledPid [SKIP]

https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-105424-merge-dd30dcce610b4a389e/System.Diagnostics.Process.Tests/1/console.4d1998ff.log?helixlogtype=result

@am11

am11 commented Jul 25, 2024

Copy link
Copy Markdown
Member

Yeah, the SkipOnPlatform line(s) probably need adjustment. I think these tests should now pass on FreeBSD and OSX.

Feel free to merge both tests into one and delete the [Skip line here.

@Thefrank, a heads-up for the next test run on FreeBSD after this PR is merged.

@gwr

gwr commented Jul 25, 2024

Copy link
Copy Markdown
Contributor Author

In CI, this test is failing on osx with your changes:

    System.Diagnostics.Tests.ProcessTests.MinWorkingSet_GetMacos_ThrowsPlatformSupportedException [FAIL]
    System.Diagnostics.Tests.ProcessTests.TestProcessRecycledPid [SKIP]

https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-105424-merge-dd30dcce610b4a389e/System.Diagnostics.Process.Tests/1/console.4d1998ff.log?helixlogtype=result

Thanks. Clearly the fix in Process.BSD.cs needs testing on OSX and FreBSD.
I've taken a stab at what I think will be needed to fix it, pushed to the PR.

@gwr gwr force-pushed the bsd-ws-limits branch from f46bebc to f064815 Compare July 25, 2024 15:23
// XXX This appears to be testing for incorrect behavoir which has been fixed.
// XXX See https://github.com/dotnet/runtime/issues/105422
// The correct exception for a new process is: InvalidOperationException
#if 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this #if 0 not allowed? I don't mean for it to stay long term, just until testing is complete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wouldn't merge this, if that's what you mean. If you want to experiment with it in CI, that's fine. I'm going to move the PR to be draft until it's ready.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, though I was hoping the CI stuff could help me with some of this, and now it seems that doesn't happen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI still runs on drafts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK. I guess I misunderstood what I saw on the web page. Thx.

@gwr

gwr commented Jul 27, 2024

Copy link
Copy Markdown
Contributor Author

I reorganized the changes related to this so it can go after #105403

@gwr gwr force-pushed the bsd-ws-limits branch 2 times, most recently from 5b1ce56 to 7115d6d Compare July 28, 2024 00:37
@gwr

gwr commented Aug 18, 2024

Copy link
Copy Markdown
Contributor Author

Rebased onto main

@gwr gwr force-pushed the bsd-ws-limits branch 2 times, most recently from 311df71 to f72eec3 Compare August 21, 2024 22:01
@gwr gwr requested a review from am11 August 21, 2024 22:02
Comment thread src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs Outdated
Fixes issue dotnet#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.
@am11

am11 commented Aug 22, 2024

Copy link
Copy Markdown
Member

@stephentoub please give it another pass. :) (the temporary blocks were removed)

@gwr

gwr commented Aug 22, 2024

Copy link
Copy Markdown
Contributor Author

Can anyone tell me what to do about the two runtime checks that reported failure?

@gwr

gwr commented Aug 28, 2024

Copy link
Copy Markdown
Contributor Author

nudge 2

@gwr

gwr commented Sep 12, 2024

Copy link
Copy Markdown
Contributor Author

nudge 3

@am11

am11 commented Sep 12, 2024

Copy link
Copy Markdown
Member

Can anyone tell me what to do about the two runtime checks that reported failure?

When Build Analysis leg is green, that means the remaining ones are known failures unrelated to your changes.

@marek-safar marek-safar added os-freebsd FreeBSD OS and removed os-freebsd FreeBSD OS os-mac-os-x macOS aka OSX labels Oct 21, 2024
@am11 am11 added the os-mac-os-x macOS aka OSX label Oct 21, 2024
@am11

am11 commented Oct 21, 2024

Copy link
Copy Markdown
Member

@marek-safar it applies to both of those operating systems.

@danmoseley

Copy link
Copy Markdown
Contributor

@stephentoub this seems good to go?

@gwr

gwr commented Dec 19, 2024

Copy link
Copy Markdown
Contributor Author

Nudge...

@stephentoub stephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, otherwise LGTM. Thanks.

@stephentoub stephentoub merged commit 02ac51e into dotnet:main May 29, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 28, 2025
@gwr gwr deleted the bsd-ws-limits branch September 11, 2025 12:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Diagnostics.Process community-contribution Indicates that the PR has been added by a community member os-freebsd FreeBSD OS os-mac-os-x macOS aka OSX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Diagnostics.Tests.ProcessTests.MaxWorkingSet_GetNotStarted wrong exception code on BSD-ish systems

5 participants