如何在 Akka.Net 中停止 TestProbe

How to stop TestProbe in Akka.Net

我需要测试我的演员是否对 Terminated 消息做出正确反应,我使用 TestProbe 来模拟它是 children。但出于某种原因,我无法阻止 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() 

感谢@Horusiath,此代码有效

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