From aa4a0dbcbb56ab551acc588fa008e4271ffe2fb2 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 21 Sep 2020 14:28:38 +0200 Subject: [PATCH] clearAll when creating new EventSourcedBehaviorTestKit, #29609 (#29634) * issue could be reproduced with sleep(200) before the persistenceTestKit.clearByPersistenceId in EventSourcedBehaviorTestKitImpl * problem is that there is a race condition betwen that clear and that the EventSourcedBehavior is starting concurrently, which can result in that the EventSourcedBehavior may see events from previous test if using same persistenceId * solution is to clearAll before starting the EventSourcedBehavior --- .../testkit/internal/EventSourcedBehaviorTestKitImpl.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/akka-persistence-testkit/src/main/scala/akka/persistence/testkit/internal/EventSourcedBehaviorTestKitImpl.scala b/akka-persistence-testkit/src/main/scala/akka/persistence/testkit/internal/EventSourcedBehaviorTestKitImpl.scala index 12902ee9d8..02bea0a62d 100644 --- a/akka-persistence-testkit/src/main/scala/akka/persistence/testkit/internal/EventSourcedBehaviorTestKitImpl.scala +++ b/akka-persistence-testkit/src/main/scala/akka/persistence/testkit/internal/EventSourcedBehaviorTestKitImpl.scala @@ -81,6 +81,7 @@ import akka.persistence.typed.internal.EventSourcedBehaviorImpl private def system: ActorSystem[_] = actorTestKit.system override val persistenceTestKit: PersistenceTestKit = PersistenceTestKit(system) + persistenceTestKit.clearAll() private val probe = actorTestKit.createTestProbe[Any]() private val stateProbe = actorTestKit.createTestProbe[State]() @@ -99,8 +100,6 @@ import akka.persistence.typed.internal.EventSourcedBehaviorImpl private var emptyStateVerified = false - persistenceTestKit.clearByPersistenceId(persistenceId.id) - override def runCommand(command: Command): CommandResult[Command, Event, State] = { if (serializationSettings.enabled && serializationSettings.verifyCommands) verifySerializationAndThrow(command, "Command")