diff --git a/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala b/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala index c5461de86b..0d2688044c 100644 --- a/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala +++ b/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala @@ -17,6 +17,7 @@ import akka.testkit.ImplicitSender import scala.concurrent.duration._ import akka.actor.FSM import akka.actor.ActorRef +import akka.testkit.TestKitExtension import akka.testkit.TestProbe import akka.actor.ActorIdentity import akka.actor.Identify @@ -49,10 +50,18 @@ class ReliableProxySpec extends MultiNodeSpec(ReliableProxySpec) with STMultiNod def expectState(s: State) = expectMsg(FSM.CurrentState(proxy, s)) def expectTransition(s1: State, s2: State) = expectMsg(FSM.Transition(proxy, s1, s2)) + def expectTransition(max: FiniteDuration, s1: State, s2: State) = expectMsg(max, FSM.Transition(proxy, s1, s2)) def sendN(n: Int) = (1 to n) foreach (proxy ! _) def expectN(n: Int) = (1 to n) foreach { n ⇒ expectMsg(n); lastSender should equal(target) } + // avoid too long timeout for expectNoMsg when using dilated timeouts, because + // blackhole will trigger failure detection + val expectNoMsgTimeout = { + val timeFactor = TestKitExtension(system).TestTimeFactor + if (timeFactor > 1.0) (1.0 / timeFactor).seconds else 1.second + } + "A ReliableProxy" must { "initialize properly" in { @@ -118,10 +127,8 @@ class ReliableProxySpec extends MultiNodeSpec(ReliableProxySpec) with STMultiNod runOn(local) { testConductor.blackhole(local, remote, Direction.Send).await sendN(100) - within(1 second) { - expectTransition(Idle, Active) - expectNoMsg - } + expectTransition(1 second, Idle, Active) + expectNoMsg(expectNoMsgTimeout) } enterBarrier("test2a") @@ -134,7 +141,7 @@ class ReliableProxySpec extends MultiNodeSpec(ReliableProxySpec) with STMultiNod runOn(local) { testConductor.passThrough(local, remote, Direction.Send).await - within(5 seconds) { expectTransition(Active, Idle) } + expectTransition(5 seconds, Active, Idle) } runOn(remote) { within(1 second) { @@ -149,10 +156,8 @@ class ReliableProxySpec extends MultiNodeSpec(ReliableProxySpec) with STMultiNod runOn(local) { testConductor.blackhole(local, remote, Direction.Receive).await sendN(100) - within(1 second) { - expectTransition(Idle, Active) - expectNoMsg - } + expectTransition(1 second, Idle, Active) + expectNoMsg(expectNoMsgTimeout) } runOn(remote) { within(1 second) { @@ -164,7 +169,7 @@ class ReliableProxySpec extends MultiNodeSpec(ReliableProxySpec) with STMultiNod runOn(local) { testConductor.passThrough(local, remote, Direction.Receive).await - within(5 seconds) { expectTransition(Active, Idle) } + expectTransition(5 seconds, Active, Idle) } enterBarrier("test3b") @@ -189,7 +194,7 @@ class ReliableProxySpec extends MultiNodeSpec(ReliableProxySpec) with STMultiNod within(5 seconds) { expectN(50) } - expectNoMsg(1 second) + expectNoMsg(expectNoMsgTimeout) } enterBarrier("test4")