Merge pull request #6088 from vector-im/michaelk/fix_forward_pagination_test

In TimelineForwardPaginationTest, explicitly test for the events we expect
This commit is contained in:
Michael Kaye 2022-05-18 16:50:09 +01:00 committed by GitHub
commit d57841c0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View File

@ -140,9 +140,24 @@ class TimelineForwardPaginationTest : InstrumentedTest {
aliceTimeline.hasMoreToLoad(Timeline.Direction.BACKWARDS).shouldBeFalse() aliceTimeline.hasMoreToLoad(Timeline.Direction.BACKWARDS).shouldBeFalse()
assertEquals(EventType.STATE_ROOM_CREATE, snapshot.lastOrNull()?.root?.getClearType()) assertEquals(EventType.STATE_ROOM_CREATE, snapshot.lastOrNull()?.root?.getClearType())
// 6 for room creation item (backward pagination), 1 for the context, and 50 for the forward pagination
// 6 + 1 + 50 // We explicitly test all the types we expect here, as we expect 51 messages and "some" state events
assertEquals(57, snapshot.size) // But state events can change over time. So this acts as a kinda documentation of what we expect and
// provides a good error message if it doesn't match
val snapshotTypes = mutableMapOf<String?, Int>()
snapshot.groupingBy { it -> it.root.type }.eachCountTo(snapshotTypes)
// Some state events on room creation
assertEquals("m.room.name", 1, snapshotTypes.remove("m.room.name"))
assertEquals("m.room.guest_access", 1, snapshotTypes.remove("m.room.guest_access"))
assertEquals("m.room.history_visibility", 1, snapshotTypes.remove("m.room.history_visibility"))
assertEquals("m.room.join_rules", 1, snapshotTypes.remove("m.room.join_rules"))
assertEquals("m.room.power_levels", 1, snapshotTypes.remove("m.room.power_levels"))
assertEquals("m.room.create", 1, snapshotTypes.remove("m.room.create"))
assertEquals("m.room.member", 1, snapshotTypes.remove("m.room.member"))
// 50 from pagination + 1 context
assertEquals("m.room.message", 51, snapshotTypes.remove("m.room.message"))
assertEquals("Additional events found in timeline", setOf<String>(), snapshotTypes.keys)
} }
// Alice paginates once again FORWARD for 50 events // Alice paginates once again FORWARD for 50 events
@ -152,8 +167,8 @@ class TimelineForwardPaginationTest : InstrumentedTest {
val snapshot = runBlocking { val snapshot = runBlocking {
aliceTimeline.awaitPaginate(Timeline.Direction.FORWARDS, 50) aliceTimeline.awaitPaginate(Timeline.Direction.FORWARDS, 50)
} }
// 6 for room creation item (backward pagination),and numberOfMessagesToSend (all the message of the room) // 7 for room creation item (backward pagination),and numberOfMessagesToSend (all the message of the room)
snapshot.size == 6 + numberOfMessagesToSend && snapshot.size == 7 + numberOfMessagesToSend &&
snapshot.checkSendOrder(message, numberOfMessagesToSend, 0) snapshot.checkSendOrder(message, numberOfMessagesToSend, 0)
// The timeline is fully loaded // The timeline is fully loaded

View File

@ -74,8 +74,12 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
Timber.w(" event ${it.root}") Timber.w(" event ${it.root}")
} }
// Ok, we have the 8 first messages of the initial sync (room creation and bob invite and join events) // Ok, we have the 9 first messages of the initial sync (room creation and bob invite and join events)
snapshot.size == 8 // create
// join alice
// power_levels, join_rules, history_visibility, guest_access, name
// invite, join bob
snapshot.size == 9
} }
bobTimeline.addListener(eventsListener) bobTimeline.addListener(eventsListener)
@ -192,7 +196,7 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
Timber.w(" event ${it.root}") Timber.w(" event ${it.root}")
} }
snapshot.size == 44 // 8 + 1 + 35 snapshot.size == 45 // 9 + 1 + 35
} }
bobTimeline.addListener(eventsListener) bobTimeline.addListener(eventsListener)
@ -220,8 +224,8 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
// Bob can see the first event of the room (so Back pagination has worked) // Bob can see the first event of the room (so Back pagination has worked)
snapshot.lastOrNull()?.root?.getClearType() == EventType.STATE_ROOM_CREATE && snapshot.lastOrNull()?.root?.getClearType() == EventType.STATE_ROOM_CREATE &&
// 8 for room creation item 60 message from Alice // 9 for room creation item 60 message from Alice
snapshot.size == 68 && // 8 + 60 snapshot.size == 69 && // 9 + 60U
snapshot.checkSendOrder(secondMessage, 30, 0) && snapshot.checkSendOrder(secondMessage, 30, 0) &&
snapshot.checkSendOrder(firstMessage, 30, 30) snapshot.checkSendOrder(firstMessage, 30, 30)
} }