我有以下 C# 代码来测试 AKKA.NET 演员的行为。该语句productActor.Tell(new ChangeActiveStatus(true));
预计将是一个阻塞调用(TestKit 根据此博客将其设为同步调用),但我看到它立即返回。结果,第二次测试失败,尽管 ActiveStatus 稍后会更改。
[TestMethod]
public void ProductActorUnitTests_CheckFor_ActiveStatusChanged()
{
var productActor = ActorOfAsTestActorRef<ProductActor>();
Assert.IsTrue(ProductActor.UnderlyingActor.ActiveStatus == false, "The initial ActiveStatus is expected to be FALSE.");
productActor.Tell(new ChangeActiveStatus(true));
Assert.IsTrue(productActor.UnderlyingActor.ActiveStatus == true, "The new ActiveStatus is expected to be TRUE.");
}
****** 更新 *****
以下带有 Thread.Sleep(10000) 的代码成功:
[TestMethod]
public void ProductActorUnitTests_CheckFor_ActiveStatusChanged()
{
var productActor = ActorOfAsTestActorRef<ProductActor>();
Assert.IsTrue(ProductActor.UnderlyingActor.ActiveStatus == false, "The initial ActiveStatus is expected to be FALSE.");
productActor.Tell(new ChangeActiveStatus(true));
Thread.Sleep(10000);
Assert.IsTrue(productActor.UnderlyingActor.ActiveStatus == true, "The new ActiveStatus is expected to be TRUE.");
}