Skip to content

Commit a01fab4

Browse files
authored
test: Harden EventSourcedCleanupSpec, #549 (#584)
* would fail when the two random pids have the same slice
1 parent 7bc097b commit a01fab4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/src/test/scala/akka/persistence/r2dbc/cleanup/scaladsl/EventSourcedCleanupSpec.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ class EventSourcedCleanupSpec
5555

5656
// find two different persistenceIds that are both in the slice range 0-255 so that this test can run with
5757
// 4 data partitions
58-
private def pidsWithSliceLessThan256(entityType: String) = {
58+
private def pidsWithDifferentSlicesLessThan256(entityType: String) = {
5959
var pid1: PersistenceId = null
6060
var pid2: PersistenceId = null
61-
while (pid1 == pid2 || persistenceExt.sliceForPersistenceId(pid1.id) > 255 || persistenceExt
62-
.sliceForPersistenceId(pid2.id) > 255) {
61+
def slice1 = persistenceExt.sliceForPersistenceId(pid1.id)
62+
def slice2 = persistenceExt.sliceForPersistenceId(pid2.id)
63+
64+
while (pid1 == pid2 || slice1 == slice2 || slice1 > 255 || slice2 > 255) {
6365
pid1 = PersistenceId(entityType, UUID.randomUUID().toString)
6466
pid2 = PersistenceId(entityType, UUID.randomUUID().toString)
6567
}
@@ -393,7 +395,7 @@ class EventSourcedCleanupSpec
393395
val ackProbe = createTestProbe[Done]()
394396
val entityType = nextEntityType()
395397

396-
var (pid1, pid2) = pidsWithSliceLessThan256(entityType)
398+
var (pid1, pid2) = pidsWithDifferentSlicesLessThan256(entityType)
397399

398400
val p1 = spawn(Persister(pid1))
399401
val p2 = spawn(Persister(pid2))

0 commit comments

Comments
 (0)