如何停止Akka.Net中的TestProbe

问题描述:

我需要测试我的演员是否对Terminated消息作出正确反应,并且我使用TestProbe来嘲笑它的孩子。但由于某种原因,我不能停止TestProbe演员。下面是测试:如何停止Akka.Net中的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() 
+0

请提供方法'CreateTestProbe' – Phate01

+0

@ Phate01,它是[Akka.TestKit]的一部分(https://petabridge.com/blog/how-to-unit-test-akkadotnet-actors-akka-testkit/)framework =( – bonzaster

+0

我的错误:D也许这可以帮助你: http://*.com/questions/ 23946826/akka-testprobe-test-context-watch-terminated-handling – Phate01

感谢@Horusiath,此代码的工作

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