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
This commit is contained in:
Patrik Nordwall 2020-09-21 14:28:38 +02:00 committed by GitHub
parent cadab9388f
commit aa4a0dbcbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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")