Skip to content

Add Dispose member to MailboxProcessor #14929

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

Merged
merged 3 commits into from
Mar 20, 2023
Merged

Add Dispose member to MailboxProcessor #14929

merged 3 commits into from
Mar 20, 2023

Conversation

bmitc
Copy link
Contributor

@bmitc bmitc commented Mar 18, 2023

Closes fsharp/fslang-suggestions#1198

This rather minimal change adds a public Dispose member to the MailboxProcessor. The benefits are:

  • Better discoverability that MailboxProcessor implements IDisposable and thus must be disposed
  • Removes need to manually cast to IDisposable, as in (mailboxProcessor :> IDisposable).Dispose() before disposing

Please see the above linked suggestion for more details.

Some questions:

  1. Is the documentation I added sufficient?
  2. Are there examples I should be updating? I'm not sure where or how to find them.
@bmitc bmitc requested a review from a team as a code owner March 18, 2023 20:34
@bmitc
Copy link
Contributor Author

bmitc commented Mar 19, 2023

I am unsure how to solve the failing tests. Here's the error:

  Failed FSharp.Core.UnitTests.Portable.SurfaceArea.SurfaceAreaTest.VerifySurfaceAreaFSharpCore [239 ms]
  Error Message:
   System.Exception : Assembly: FSharp.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

              Expected and actual surface area don't match. To see the delta, run:
                  windiff D:\a\_work\1\s\tests\FSharp.Core.UnitTests\FSharp.Core.SurfaceArea.netstandard20.release.bsl D:\a\_work\1\s\artifacts\bin\FSharp.Core.UnitTests\Release\net472\FSharp.Core.SurfaceArea.netstandard20.release.out

              Unexpectedly missing (expected, not actual):

Unexpectedly present (actual, not expected):
    Microsoft.FSharp.Control.FSharpMailboxProcessor`1[TMsg]: Void Dispose()

Previously, the error message was "Unexpectedly present", and so I edited the [FSharp.Core.SurfaceArea.netstandard21.release.bsl](https://github.com/dotnet/fsharp/pull/14929/commits/bd91ecb01262c9c434185612afad8e21b2e26e51) to include the MailboxProcessor's new Dispose method. (This was a guess after trying to debug this issue locally.)

Could someone help me out here and explain what the surface area test is doing and how I should go about fixing it? It would be much appreciated. Thank you!

@smoothdeveloper
Copy link
Contributor

@bmitc, if you copy the .out over the .bsl that are pointed by the test output, you should be able to see the diff when you are about to commit the difference.

@bmitc
Copy link
Contributor Author

bmitc commented Mar 19, 2023

Thank you for the confirmation that that is the appropriate thing to do! My previous commit was just a guess toward that end, but I wasn't for sure if something was generating the BSL file, and just copying over the actual output over the expected felt like "cheating" the test. Haha.

What does BSL stand for? Is it just there to keep track of the available types, functions, members, etc. that are exposed by the DLLs and make sure the DLLs expose these as expected with new builds?

@psfinaki
Copy link
Member

@bmitc BSL means baseline. We have some obscure acronyms in the repo - should have been BSLN, right? :) Added a PR to clarify this a bit.

Otherwise, your understanding is correct. You can read a bit more in the TESTGUIDE.

And thanks for the contribution!

@abonie abonie merged commit 3c5e338 into dotnet:main Mar 20, 2023
@bmitc
Copy link
Contributor Author

bmitc commented Mar 20, 2023

Thank you for the clarification @psfinaki! I had later read about the BSL here, but thanks for the updating the docs! Thanks for the help everyone and for merging.

Also, I was looking to add a unit test for Dispose. I noted that there is this test, but there are no assertions. I was thinking about testing for the ObjectDisposedException, but I am not entirely sure of the mechanics there. According to the docs, it should be thrown anytime an IDisposable has been disposed and a member is called on the object, but I can't get anything in F# to actually throw that exception.

Are there any ideas as to a proper test for Dispose? I suppose one approach is to just have a test that at least calls Dispose?

@psfinaki
Copy link
Member

@bmitc so AFAIU the test you link just checks that nothing blows up. I think xUnit now doesn't have things like Assert.DoesNotThrow hence the test looks how it looks.

Otherwise, I've found this thread about testing the Dispose method. I'm all up for testing in general, but if you think it's an overkill, that's fine.

kant2002 pushed a commit to kant2002/fsharp that referenced this pull request Apr 1, 2023
* Add `Dispose` member to `MailboxProcessor`

* Update FSharp.Core.SurfaceArea.netstandard21.release.bsl

* Update FSharp.Core.SurfaceArea.netstandard20.release.bsl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants