diff --git a/akka-cluster-sharding/src/multi-jvm/scala/akka/cluster/sharding/ClusterShardingQueriesSpec.scala b/akka-cluster-sharding/src/multi-jvm/scala/akka/cluster/sharding/ClusterShardingQueriesSpec.scala index 02e3846a54..bf47720c0b 100644 --- a/akka-cluster-sharding/src/multi-jvm/scala/akka/cluster/sharding/ClusterShardingQueriesSpec.scala +++ b/akka-cluster-sharding/src/multi-jvm/scala/akka/cluster/sharding/ClusterShardingQueriesSpec.scala @@ -8,7 +8,6 @@ import scala.concurrent.duration._ import com.typesafe.config.ConfigFactory import org.scalatest.concurrent.ScalaFutures - import akka.actor.Props import akka.testkit.TestProbe @@ -29,8 +28,7 @@ object ClusterShardingQueriesSpec { val shardTypeName = "DatatypeA" } -object ClusterShardingQueriesSpecConfig - extends MultiNodeClusterShardingConfig(additionalConfig = """ +object ClusterShardingQueriesSpecConfig extends MultiNodeClusterShardingConfig(additionalConfig = s""" akka.log-dead-letters-during-shutdown = off akka.cluster.sharding { shard-region-query-timeout = 2ms @@ -113,15 +111,17 @@ abstract class ClusterShardingQueriesSpec runOn(busy, second, third) { val probe = TestProbe() val region = ClusterSharding(system).shardRegion(shardTypeName) - region.tell(ShardRegion.GetClusterShardingStats(10.seconds), probe.ref) - val regions = probe.expectMsgType[ShardRegion.ClusterShardingStats].regions - regions.size shouldEqual 3 - val timeouts = numberOfShards / regions.size + awaitAssert({ + region.tell(ShardRegion.GetClusterShardingStats(10.seconds), probe.ref) + val regions = probe.expectMsgType[ShardRegion.ClusterShardingStats].regions + regions.size shouldEqual 3 + val timeouts = numberOfShards / regions.size - // 3 regions, 2 shards per region, all 2 shards/region were unresponsive - // within shard-region-query-timeout, which only on first is 0ms - regions.values.map(_.stats.size).sum shouldEqual 4 - regions.values.map(_.failed.size).sum shouldEqual timeouts + // 3 regions, 2 shards per region, all 2 shards/region were unresponsive + // within shard-region-query-timeout, which only on first is 0ms + regions.values.map(_.stats.size).sum shouldEqual 4 + regions.values.map(_.failed.size).sum shouldEqual timeouts + }, max = 10.seconds) } enterBarrier("received failed stats from timed out shards vs empty") } @@ -130,21 +130,24 @@ abstract class ClusterShardingQueriesSpec runOn(busy) { val probe = TestProbe() val region = ClusterSharding(system).shardRegion(shardTypeName) - region.tell(ShardRegion.GetShardRegionState, probe.ref) - val state = probe.expectMsgType[ShardRegion.CurrentShardRegionState] - state.shards.isEmpty shouldEqual true - state.failed.size shouldEqual 2 + awaitAssert({ + region.tell(ShardRegion.GetShardRegionState, probe.ref) + val state = probe.expectMsgType[ShardRegion.CurrentShardRegionState] + state.shards.isEmpty shouldEqual true + state.failed.size shouldEqual 2 + }, max = 10.seconds) } enterBarrier("query-timeout-on-busy-node") runOn(second, third) { val probe = TestProbe() val region = ClusterSharding(system).shardRegion(shardTypeName) - - region.tell(ShardRegion.GetShardRegionState, probe.ref) - val state = probe.expectMsgType[ShardRegion.CurrentShardRegionState] - state.shards.size shouldEqual 2 - state.failed.isEmpty shouldEqual true + awaitAssert({ + region.tell(ShardRegion.GetShardRegionState, probe.ref) + val state = probe.expectMsgType[ShardRegion.CurrentShardRegionState] + state.shards.size shouldEqual 2 + state.failed.isEmpty shouldEqual true + }, max = 10.seconds) } enterBarrier("done") }