From 47193f1a026ae26e1b4d4326c71b44889219c150 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 18 Dec 2024 14:31:34 +0100 Subject: [PATCH] test: make `test_room_keys_received_on_notification_client_trigger_redecryption` more stable When starting to back-paginate, in this test, we: - either have a previous-batch token, that points to the first event *before* the message was sent, - or have no previous-batch token, because we stopped sync before receiving the first sync result. Because of the behavior introduced in 944a9220, we don't restart back-paginating from the end, if we've reached the start. Now, if we are in the case described by the first bullet item, then we may backpaginate until the start of the room, and stop then, because we've back-paginated all events. And so we'll never see the message sent by Alice after we stopped sync'ing. One solution to get to the desired state is to clear the internal state of the room event cache, thus deleting the previous-batch token, thus causing the situation described in the second bullet item. This achieves what we want, that is, back-paginating from the end of the timeline. --- .../src/tests/timeline.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs index 0b63cfb1c26..7a2dcdc725f 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs @@ -558,12 +558,18 @@ async fn test_room_keys_received_on_notification_client_trigger_redecryption() { alice_sync.abort(); // Let's get the timeline and backpaginate to load the event. - let mut timeline = + let timeline = bob_room.timeline().await.expect("We should be able to get a timeline for our room"); let mut item = None; for _ in 0..10 { + { + // Clear any previously received previous-batch token. + let (room_event_cache, _drop_handles) = bob_room.event_cache().await.unwrap(); + room_event_cache.clear().await.unwrap(); + } + timeline .paginate_backwards(50) .await @@ -572,10 +578,9 @@ async fn test_room_keys_received_on_notification_client_trigger_redecryption() { if let Some(timeline_item) = timeline.item_by_event_id(&event_id).await { item = Some(timeline_item); break; - } else { - timeline = bob_room.timeline().await.expect("We should be able to reset our timeline"); - sleep(Duration::from_millis(100)).await } + + sleep(Duration::from_millis(100)).await } let item = item.expect("The event should be in the timeline by now");