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

Demonstrate bug by breaking test #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vicero
Copy link

@vicero vicero commented Feb 11, 2022

I was trying to use Serilog to log properties on the ambient context and noticed that none of the properties were being logged. Debugging showed that the Dispose method in Serilog's Enricher was being called almost immediately in an actor that binds to an async computation.

I forked this repo and created a failing test by adding an async binding to an actor that is testing dispose.

Failed: Expected a message of type System.Int32, but received {disposed-0} (type System.String) instead  from [akka://test-system/user/actor#535163074...

Xunit.Sdk.TrueException
Failed: Expected a message of type System.Int32, but received {disposed-0} (type System.String) instead  from [akka://test-system/user/actor#535163074]
Expected: True
Actual:   False
   at Akka.TestKit.Xunit2.XunitAssertions.Fail(String format, Object[] args)
   at Akka.TestKit.TestKitBase.InternalExpectMsgEnvelope[T](Nullable`1 timeout, Action`2 assert, String hint, Boolean shouldLog)
   at Akka.TestKit.TestKitBase.InternalExpectMsgEnvelope[T](Nullable`1 timeout, Action`1 msgAssert, Action`1 senderAssert, String hint)
   at Akka.TestKit.TestKitBase.InternalExpectMsg[T](Nullable`1 timeout, Action`1 msgAssert, String hint)
   at Akka.TestKit.TestKitBase.ExpectMsg[T](T message, Nullable`1 timeout, String hint)
   at Akkling.TestKit.expectMsg[t](TestKit tck, t msg) in /home/james/Locai/Akkling/src/Akkling.TestKit/TestKit.fs:line 47
   at Akkling.Tests.ComputationExpression.Actor computation use disposes [email protected](TestKit tck) in /home/james/Locai/Akkling/tests/Akkling.Tests/ComputationExpressions.fs:line 210
   at Akkling.TestKit.testDefault[a](FSharpFunc`2 fn) in /home/james/Locai/Akkling/src/Akkling.TestKit/TestKit.fs:line 37
   at Akkling.Tests.ComputationExpression.Actor computation use disposes objects() in /home/james/Locai/Akkling/tests/Akkling.Tests/ComputationExpressions.fs:line 189

I'm not sure of the resolution or I would have included it in the pull request, but I am happy to help in any way I can!

@sbacquet
Copy link

You can work around it :

                do! async {
                    use x =
                        { new IDisposable with
                            member _.Dispose () =
                                sender <! (sprintf "disposed-%d" msg)
                        }
                    do! Async.Sleep(1)
                    ctx.Sender() <! msg
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants