如何在Akka.Net中停止TestProbe

时间:2017-01-09 13:19:40

标签: c# akka akka.net

我需要测试我的演员对Terminated消息的正确反应,并使用TestProbe来模仿它的孩子。但出于某种原因,我无法阻止TestProbe演员。这是测试:

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

结果如下:

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 个答案:

答案 0 :(得分:0)

感谢@Horusiath,此代码有效

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