Horusiath / Akkling

Experimental F# typed API for Akka.NET
Apache License 2.0
225 stars 45 forks source link

Demonstrate bug by breaking test #153

Open vicero opened 2 years ago

vicero commented 2 years ago

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 objects@189.Invoke(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 commented 1 month ago

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
                }