From 071a074ccbc2a9beffe4f00af15dc98334d9f53e Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Fri, 13 Aug 2021 15:31:58 +0000 Subject: [PATCH] Fix StartEntitySpec instability The old logic allowed a race condition where the 'StartEntity' from the test arrived at the ShardRegion before the termination of the actor did, causing it to ignore the `StartEntity`. --- .../scala/akka/cluster/sharding/StartEntitySpec.scala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/akka-cluster-sharding/src/test/scala/akka/cluster/sharding/StartEntitySpec.scala b/akka-cluster-sharding/src/test/scala/akka/cluster/sharding/StartEntitySpec.scala index 3135a64205..2eb3d7f302 100644 --- a/akka-cluster-sharding/src/test/scala/akka/cluster/sharding/StartEntitySpec.scala +++ b/akka-cluster-sharding/src/test/scala/akka/cluster/sharding/StartEntitySpec.scala @@ -129,11 +129,17 @@ class StartEntitySpec extends AkkaSpec(StartEntitySpec.config) with ImplicitSend sharding ! EntityEnvelope("1", "ping") expectMsg("pong") val entity = lastSender - watch(entity) // stop without passivation entity ! "just-stop" - expectTerminated(entity) + + // Make sure the shard has processed the termination + awaitAssert({ + sharding ! ShardRegion.GetShardRegionState + val state = expectMsgType[ShardRegion.CurrentShardRegionState] + state.shards should have size (1) + state.shards.head.entityIds should ===(Set()) + }) // the backoff is 10s by default, so plenty time to // bypass region and send start entity directly to shard