Merge pull request #30542 from raboof/improve-InmemPersistentActorSpec-stability

Improve InmemPersistentActorSpec stability
This commit is contained in:
Patrik Nordwall 2021-08-17 08:28:20 +02:00 committed by GitHub
commit f7521f0587
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1214,13 +1214,14 @@ abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(confi
// that commands are processed before events have been persisted. Therefore, we // that commands are processed before events have been persisted. Therefore, we
// retry until eventually... // retry until eventually...
eventually { eventually {
val probe = TestProbe()
val persistentActor = asyncPersistPersistentActor val persistentActor = asyncPersistPersistentActor
persistentActor ! Cmd("x") probe.send(persistentActor, Cmd("x"))
persistentActor ! Cmd("y") probe.send(persistentActor, Cmd("y"))
expectMsg("x") probe.expectMsg("x")
expectMsg("y") // "y" command was processed before event persisted probe.expectMsg("y") // "y" command was processed before event persisted
expectMsg("x-1") probe.expectMsg("x-1")
expectMsg("y-2") probe.expectMsg("y-2")
} }
} }
"support multiple persistAsync calls for one command, and execute them 'when possible', not hindering command processing" in { "support multiple persistAsync calls for one command, and execute them 'when possible', not hindering command processing" in {
@ -1424,13 +1425,18 @@ abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(confi
test(deferringSyncWithAsyncPersistActor) test(deferringSyncWithAsyncPersistActor)
} }
"handle new messages before deferAsync handler is called" in { "handle new messages before deferAsync handler is called" in {
val persistentActor = deferringAsyncActor // Depending on timing, 'x-defer' might arrive before or after 'y'.
persistentActor ! Cmd("x") // This test is meant to demonstrate that 'x-defer' *may* arrive later.'
persistentActor ! Cmd("y") eventually {
expectMsg("x") val probe = TestProbe()
expectMsg("y") // "y" command was processed before event persisted val persistentActor = deferringAsyncActor
expectMsg("x-defer") probe.send(persistentActor, Cmd("x"))
expectMsg("y-defer") probe.send(persistentActor, Cmd("y"))
probe.expectMsg("x")
probe.expectMsg("y") // "y" command was processed before event persisted
probe.expectMsg("x-defer")
probe.expectMsg("y-defer")
}
} }
"handle defer sequentially" in { "handle defer sequentially" in {
val persistentActor = deferringSyncActor val persistentActor = deferringSyncActor