How to stop TestProbe in Akka.Net

506 Views Asked by At

I need to test that my actor properly react on Terminated message, and I use TestProbe to mock it's children. But for some reason I can't stop TestProbe actors. Here is the test:

    [Test]
    public void TestProbeStopTest()
    {
        var probe = CreateTestProbe("Test");
        Watch(probe);
        Sys.Stop(probe);
        ExpectTerminated(probe);
    }

And here is a result:

Failed: Timeout 00:00:03 while waiting for a message of type Akka.Actor.Terminated Terminated Akka.TestKit.TestProbe. 
   at NUnit.Framework.Assert.Fail(String message, 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.ExpectTerminated(IActorRef target, Nullable`1 timeout, String hint)
   at Actors.Tests.Common.RootActorTests.TestProbeStopTest() 
1

There are 1 best solutions below

0
On BEST ANSWER

Thanks @Horusiath, this code works

[Test]
public void TestProbeStopTest()
{
    var probe = CreateTestProbe("Test");
    Watch(probe.Ref);
    Sys.Stop(probe.Ref);
    ExpectTerminated(probe.Ref);
}