Stabilise InmemPersistentActorSpec (#30499)

This commit is contained in:
Ignasi Marimon-Clos 2021-08-06 18:44:26 +02:00 committed by GitHub
parent 71263db0cc
commit cb97ae1240
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,13 +11,13 @@ import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.Random
import scala.util.control.NoStackTrace
import scala.annotation.nowarn
import com.typesafe.config.{ Config, ConfigFactory }
import com.typesafe.config.{ Config, ConfigFactory }
import akka.actor._
import akka.persistence.PersistentActorSpec._
import akka.testkit.{ EventFilter, ImplicitSender, TestLatch, TestProbe }
import org.scalatest.concurrent.Eventually
object PersistentActorSpec {
@ -944,7 +944,7 @@ object PersistentActorSpec {
}
}
abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(config) with ImplicitSender {
abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(config) with ImplicitSender with Eventually {
import PersistentActorSpec._
@ -1210,13 +1210,18 @@ abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(confi
expectMsg(5)
}
"be able to opt-out from stashing messages until all events have been processed" in {
val persistentActor = asyncPersistPersistentActor
persistentActor ! Cmd("x")
persistentActor ! Cmd("y")
expectMsg("x")
expectMsg("y") // "y" command was processed before event persisted
expectMsg("x-1")
expectMsg("y-2")
// There's a race between "y" and "x-1", but only if we receive "y" we will prove
// that commands are processed before events have been persisted. Therefore, we
// retry until eventually...
eventually {
val persistentActor = asyncPersistPersistentActor
persistentActor ! Cmd("x")
persistentActor ! Cmd("y")
expectMsg("x")
expectMsg("y") // "y" command was processed before event persisted
expectMsg("x-1")
expectMsg("y-2")
}
}
"support multiple persistAsync calls for one command, and execute them 'when possible', not hindering command processing" in {
val persistentActor = asyncPersistThreeTimesPersistentActor