2017-01-09 64 views
0

我需要測試我的演員是否對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://stackoverflow.com/questions/ 23946826/akka-testprobe-test-context-watch-terminated-handling – Phate01

回答

0

感謝@Horusiath,此代碼的工作

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