- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 akka 2.3.9 documentation有一个警告:
Any message send from a
TestProbe
to another actor which runs on theCallingThreadDispatcher
runs the risk of dead-lock, if that other actor might also send to this probe. The implementation ofTestProbe.watch
andTestProbe.unwatch
will also send a message to the watchee, which means that it is dangerous to try watching e.g.TestActorRef
from aTestProbe
.
我尝试使用 TestProbe
和 TestActorRef
在测试中重现所描述的死锁情况,因为两者都使用 CallingThreadDispatcher
class DeadlockTest extends TestKit(ActorSystem()) with FunSuiteLike {
test("deadlock attempt") {
val b = TestProbe()
val a = TestActorRef(new Actor {
override def preStart() = b.ref ! "pre"
def receive = {
case msg =>
sender ! msg
context.stop(self)
}
})
b.watch(a)
b.send(a, "foo")
b.expectMsg("pre")
b.expectMsg("foo")
b.expectTerminated(a)
b.unwatch(a)
}
}
我预计测试会挂起,但它成功通过了。
警告是否仍然相关并且死锁的可能性很高还是已过时?
最佳答案
这个警告所说的竞争条件是 TestProbe 设计中固有的,但是遇到死锁的概率相当小,监视必须与向另一个方向发送消息的时间完全同时发生,并且两者都必须发生在不同的线程。由于顶级参与者的创建方式,在极少数情况下可以观察到后者。
所有这些都相当棘手,并且都不适用于为 Akka Typed 编写和执行测试的方式,我期待着何时成为唯一使用的模式。
关于scala - TestActorRef 死锁可能性是否仍然相关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806011/
在 akka 2.3.9 documentation有一个警告: Any message send from a TestProbe to another actor which runs on th
我正在尝试为以下 Actor 编写我的第一个 ScalaTest object Runner { def props(race: Race) = Props(classOf[Runner], ra
我正在尝试获得这样的 TestActorRef class NotifySenderTest(_system: ActorSystem) extends TestKit(_system) with I
我是 actors 的新手,我正在学习如何使用 TestActorRef 测试 actors 我的 Actor 代码: package actors import actors.GreetingAct
Akka Testing docs给出以下创建 TestActorRef 的方法: import akka.testkit.TestActorRefval actorRef = TestActorRe
我遇到了一个扩展 Stash 的 actor 的问题,并且在一个简单的 ActorSystem 中使用 actorOf 实例化它时效果很好。现在我实际上想在我的程序中使用它们之前为我的 stashin
对akka Actor 来说有点新意 但希望了解 TestKit 、 TastActorRef 和 TestProbe 之间的用途和区别 在akka单元测试中使用。 我已经看到它们用于单元测试 akk
我是一名优秀的程序员,十分优秀!