Harden ClusterClientHandoverSpec #24959

The test failed timing out waiting for a cluster to remove a member. It
was nearly done. This change uses the common configuration used for
cluster tests to speed up membership changes rather than increasing the
timeout.
This commit is contained in:
Christopher Batey 2018-04-24 12:26:37 +01:00 committed by Johan Andrén
parent 59ed3b353f
commit 161d2de44a
2 changed files with 14 additions and 33 deletions

View file

@ -3,8 +3,8 @@
*/ */
package akka.cluster.client package akka.cluster.client
import akka.actor.ActorRef import akka.actor.{ ActorPath, ActorRef }
import akka.cluster.{ Cluster, ClusterReadView, MemberStatus } import akka.cluster.{ Cluster, MultiNodeClusterSpec }
import akka.remote.testconductor.RoleName import akka.remote.testconductor.RoleName
import akka.remote.testkit.{ MultiNodeConfig, MultiNodeSpec, STMultiNodeSpec } import akka.remote.testkit.{ MultiNodeConfig, MultiNodeSpec, STMultiNodeSpec }
import akka.testkit.{ ImplicitSender, TestActors } import akka.testkit.{ ImplicitSender, TestActors }
@ -28,16 +28,14 @@ object ClusterClientHandoverSpec extends MultiNodeConfig {
} }
akka.test.filter-leeway = 10s akka.test.filter-leeway = 10s
""")) """).withFallback(MultiNodeClusterSpec.clusterConfig))
} }
class ClusterClientHandoverMultiJvmNode1 extends ClusterClientHandoverSpec class ClusterClientHandoverSpecMultiJvmNode1 extends ClusterClientHandoverSpec
class ClusterClientHandoverSpecMultiJvmNode2 extends ClusterClientHandoverSpec
class ClusterClientHandoverSpecMultiJvmNode3 extends ClusterClientHandoverSpec
class ClusterClientHandoverMultiJvmNode2 extends ClusterClientHandoverSpec class ClusterClientHandoverSpec extends MultiNodeSpec(ClusterClientHandoverSpec) with STMultiNodeSpec with ImplicitSender with MultiNodeClusterSpec {
class ClusterClientHandoverMultiJvmNode3 extends ClusterClientHandoverSpec
class ClusterClientHandoverSpec extends MultiNodeSpec(ClusterClientHandoverSpec) with STMultiNodeSpec with ImplicitSender {
import ClusterClientHandoverSpec._ import ClusterClientHandoverSpec._
@ -51,29 +49,19 @@ class ClusterClientHandoverSpec extends MultiNodeSpec(ClusterClientHandoverSpec)
enterBarrier(from.name + "-joined") enterBarrier(from.name + "-joined")
} }
def clusterView: ClusterReadView = Cluster(system).readView def initialContacts: Set[ActorPath] = Set(first, second).map { r
def awaitUp(expected: Int): Unit = {
awaitAssert {
awaitAssert(clusterView.members.size should ===(expected))
awaitAssert(clusterView.members.map(_.status) should ===(Set(MemberStatus.Up)))
}
}
def initialContacts = Set(first, second).map { r
node(r) / "system" / "receptionist" node(r) / "system" / "receptionist"
} }
"A Cluster Client" should { "A Cluster Client" must {
"startup cluster with a single node" in within(30.seconds) { "startup cluster with a single node" in within(30.seconds) {
join(first, first) join(first, first)
runOn(first) { runOn(first) {
val service = system.actorOf(TestActors.echoActorProps, "testService") val service = system.actorOf(TestActors.echoActorProps, "testService")
ClusterClientReceptionist(system).registerService(service) ClusterClientReceptionist(system).registerService(service)
awaitUp(1) awaitMembersUp(1)
} }
enterBarrier("cluster-started") enterBarrier("cluster-started")
} }
@ -86,7 +74,6 @@ class ClusterClientHandoverSpec extends MultiNodeSpec(ClusterClientHandoverSpec)
clusterClient ! ClusterClient.Send("/user/testService", "hello", localAffinity = true) clusterClient ! ClusterClient.Send("/user/testService", "hello", localAffinity = true)
expectMsgType[String](3.seconds) should be("hello") expectMsgType[String](3.seconds) should be("hello")
} }
enterBarrier("established") enterBarrier("established")
} }
@ -95,9 +82,8 @@ class ClusterClientHandoverSpec extends MultiNodeSpec(ClusterClientHandoverSpec)
runOn(second) { runOn(second) {
val service = system.actorOf(TestActors.echoActorProps, "testService") val service = system.actorOf(TestActors.echoActorProps, "testService")
ClusterClientReceptionist(system).registerService(service) ClusterClientReceptionist(system).registerService(service)
awaitUp(2) awaitMembersUp(2)
} }
enterBarrier("second-up") enterBarrier("second-up")
} }
@ -107,9 +93,8 @@ class ClusterClientHandoverSpec extends MultiNodeSpec(ClusterClientHandoverSpec)
} }
runOn(second) { runOn(second) {
awaitUp(1) awaitMembersUp(1)
} }
enterBarrier("handover-done") enterBarrier("handover-done")
} }
@ -118,10 +103,7 @@ class ClusterClientHandoverSpec extends MultiNodeSpec(ClusterClientHandoverSpec)
clusterClient ! ClusterClient.Send("/user/testService", "hello", localAffinity = true) clusterClient ! ClusterClient.Send("/user/testService", "hello", localAffinity = true)
expectMsgType[String](3.seconds) should be("hello") expectMsgType[String](3.seconds) should be("hello")
} }
enterBarrier("handover-successful") enterBarrier("handover-successful")
} }
} }
} }

View file

@ -6,7 +6,6 @@ package akka.testkit.typed.scaladsl
//#manual-scheduling-simple //#manual-scheduling-simple
import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.Behaviors
import org.scalatest.WordSpecLike
import scala.concurrent.duration._ import scala.concurrent.duration._
@ -14,7 +13,7 @@ class ManualTimerExampleSpec extends AbstractActorSpec {
override def config = ManualTime.config override def config = ManualTime.config
val manualTime = ManualTime() val manualTime: ManualTime = ManualTime()
"A timer" must { "A timer" must {
"schedule non-repeated ticks" in { "schedule non-repeated ticks" in {
@ -24,7 +23,7 @@ class ManualTimerExampleSpec extends AbstractActorSpec {
val probe = TestProbe[Tock.type]() val probe = TestProbe[Tock.type]()
val behavior = Behaviors.withTimers[Tick.type] { timer val behavior = Behaviors.withTimers[Tick.type] { timer
timer.startSingleTimer("T", Tick, 10.millis) timer.startSingleTimer("T", Tick, 10.millis)
Behaviors.receive { (ctx, Tick) Behaviors.receiveMessage { _
probe.ref ! Tock probe.ref ! Tock
Behaviors.same Behaviors.same
} }