diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs index b8e30babab3..9cd83213239 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs @@ -318,11 +318,6 @@ impl TimelineItemContent { as_variant!(self, Self::UnableToDecrypt) } - #[cfg(test)] - pub(crate) fn is_redacted(&self) -> bool { - matches!(self, Self::RedactedMessage) - } - // These constructors could also be `From` implementations, but that would // allow users to call them directly, which should not be supported pub(crate) fn message( diff --git a/crates/matrix-sdk-ui/src/timeline/tests/basic.rs b/crates/matrix-sdk-ui/src/timeline/tests/basic.rs index ba7abb9f7a3..bb0adbeba00 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/basic.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/basic.rs @@ -23,7 +23,7 @@ use ruma::{ receipt::{Receipt, ReceiptThread, ReceiptType}, room::{ member::{MembershipState, RedactedRoomMemberEventContent, RoomMemberEventContent}, - message::{MessageType, RoomMessageEventContent}, + message::MessageType, name::RoomNameEventContent, topic::RedactedRoomTopicEventContent, }, @@ -280,77 +280,6 @@ async fn test_other_state() { assert_matches!(full_content, FullStateEventContent::Redacted(_)); } -#[async_test] -async fn test_dedup_pagination() { - let timeline = TestTimeline::new(); - - let event = timeline - .event_builder - .make_sync_message_event(*ALICE, RoomMessageEventContent::text_plain("o/")); - timeline.handle_live_event(SyncTimelineEvent::new(event.clone())).await; - // This cast is not actually correct, sync events aren't valid - // back-paginated events, as they are missing `room_id`. However, the - // timeline doesn't care about that `room_id` and casts back to - // `Raw` before attempting to deserialize. - timeline.handle_back_paginated_event(event.cast()).await; - - let timeline_items = timeline.controller.items().await; - assert_eq!(timeline_items.len(), 2); - assert_matches!( - timeline_items[0].kind, - TimelineItemKind::Virtual(VirtualTimelineItem::DateDivider(_)) - ); - assert_matches!(timeline_items[1].kind, TimelineItemKind::Event(_)); -} - -#[async_test] -async fn test_dedup_initial() { - let timeline = TestTimeline::new(); - - let f = &timeline.factory; - let event_a = f.text_msg("A").sender(*ALICE).into_sync(); - let event_b = f.text_msg("B").sender(*BOB).into_sync(); - let event_c = f.text_msg("C").sender(*CAROL).into_sync(); - - timeline - .controller - .add_events_at( - [ - // two events - event_a.clone(), - event_b.clone(), - // same events got duplicated in next sync response - event_a, - event_b, - // … and a new event also came in - event_c, - ] - .into_iter(), - TimelineNewItemPosition::End { origin: RemoteEventOrigin::Sync }, - ) - .await; - - let timeline_items = timeline.controller.items().await; - assert_eq!(timeline_items.len(), 4); - - assert!(timeline_items[0].is_date_divider()); - - let event1 = &timeline_items[1]; - let event2 = &timeline_items[2]; - let event3 = &timeline_items[3]; - - // Make sure the order is right. - assert_eq!(event1.as_event().unwrap().sender(), *ALICE); - assert_eq!(event2.as_event().unwrap().sender(), *BOB); - assert_eq!(event3.as_event().unwrap().sender(), *CAROL); - - // Make sure we reused IDs when deduplicating events. - assert_eq!(event1.unique_id().0, "0"); - assert_eq!(event2.unique_id().0, "1"); - assert_eq!(event3.unique_id().0, "2"); - assert_eq!(timeline_items[0].unique_id().0, "3"); -} - #[async_test] async fn test_internal_id_prefix() { let timeline = TestTimeline::with_internal_id_prefix("le_prefix_".to_owned()); diff --git a/crates/matrix-sdk-ui/src/timeline/tests/echo.rs b/crates/matrix-sdk-ui/src/timeline/tests/echo.rs index 683f643ec85..f5a85de4495 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/echo.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/echo.rs @@ -18,7 +18,7 @@ use assert_matches::assert_matches; use eyeball_im::VectorDiff; use matrix_sdk::{assert_next_matches_with_timeout, send_queue::RoomSendQueueUpdate}; use matrix_sdk_base::store::QueueWedgeError; -use matrix_sdk_test::{async_test, event_factory::EventFactory, ALICE, BOB}; +use matrix_sdk_test::{async_test, ALICE, BOB}; use ruma::{ event_id, events::{room::message::RoomMessageEventContent, AnyMessageLikeEventContent}, @@ -187,42 +187,6 @@ async fn test_remote_echo_new_position() { assert_pending!(stream); } -#[async_test] -async fn test_date_divider_duplication() { - let timeline = TestTimeline::new(); - - // Given two remote events from one day, and a local event from another day… - let f = EventFactory::new().sender(&BOB); - timeline.handle_live_event(f.text_msg("A")).await; - timeline.handle_live_event(f.text_msg("B")).await; - timeline - .handle_local_event(AnyMessageLikeEventContent::RoomMessage( - RoomMessageEventContent::text_plain("C"), - )) - .await; - - let items = timeline.controller.items().await; - assert_eq!(items.len(), 5); - assert!(items[0].is_date_divider()); - assert!(items[1].is_remote_event()); - assert!(items[2].is_remote_event()); - assert!(items[3].is_date_divider()); - assert!(items[4].is_local_echo()); - - // … when the second remote event is re-received (day still the same) - let event_id = items[2].as_event().unwrap().event_id().unwrap(); - timeline.handle_live_event(f.text_msg("B").event_id(event_id).server_ts(1)).await; - - // … it should not impact the date dividers. - let items = timeline.controller.items().await; - assert_eq!(items.len(), 5); - assert!(items[0].is_date_divider()); - assert!(items[1].is_remote_event()); - assert!(items[2].is_remote_event()); - assert!(items[3].is_date_divider()); - assert!(items[4].is_local_echo()); -} - #[async_test] async fn test_date_divider_removed_after_local_echo_disappeared() { let timeline = TestTimeline::new(); diff --git a/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs b/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs index 11fa3023721..196e61ed058 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/redaction.rs @@ -19,10 +19,7 @@ use matrix_sdk_base::deserialized_responses::SyncTimelineEvent; use matrix_sdk_test::{async_test, ALICE, BOB}; use ruma::events::{ reaction::RedactedReactionEventContent, - room::{ - message::{OriginalSyncRoomMessageEvent, RedactedRoomMessageEventContent}, - name::RoomNameEventContent, - }, + room::{message::OriginalSyncRoomMessageEvent, name::RoomNameEventContent}, FullStateEventContent, }; use stream_assert::assert_next_matches; @@ -177,56 +174,3 @@ async fn test_reaction_redaction_timeline_filter() { assert_eq!(item.reactions().len(), 0); assert_eq!(timeline.controller.items().await.len(), 2); } - -#[async_test] -async fn test_receive_unredacted() { - let timeline = TestTimeline::new(); - - let f = &timeline.factory; - - // send two events, second one redacted - timeline.handle_live_event(f.text_msg("about to be redacted").sender(&ALICE)).await; - timeline - .handle_live_redacted_message_event(&ALICE, RedactedRoomMessageEventContent::new()) - .await; - - // redact the first one as well - let items = timeline.controller.items().await; - assert!(items[0].is_date_divider()); - let fst = items[1].as_event().unwrap(); - timeline.handle_live_event(f.redaction(fst.event_id().unwrap()).sender(&ALICE)).await; - - let items = timeline.controller.items().await; - assert_eq!(items.len(), 3); - let fst = items[1].as_event().unwrap(); - let snd = items[2].as_event().unwrap(); - - // make sure we have two redacted events - assert!(fst.content.is_redacted()); - assert!(snd.content.is_redacted()); - - // send new events with the same event ID as the previous ones - timeline - .handle_live_event( - f.text_msg("unredacted #1") - .sender(*ALICE) - .event_id(fst.event_id().unwrap()) - .server_ts(fst.timestamp()), - ) - .await; - - timeline - .handle_live_event( - f.text_msg("unredacted #2") - .sender(*ALICE) - .event_id(snd.event_id().unwrap()) - .server_ts(snd.timestamp()), - ) - .await; - - // make sure we still have two redacted events - let items = timeline.controller.items().await; - assert_eq!(items.len(), 3); - assert!(items[1].as_event().unwrap().content.is_redacted()); - assert!(items[2].as_event().unwrap().content.is_redacted()); -} diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/pagination.rs b/crates/matrix-sdk-ui/tests/integration/timeline/pagination.rs index 3a2c0aeaa54..a796fc740da 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/pagination.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/pagination.rs @@ -37,7 +37,7 @@ use ruma::{ room_id, }; use serde_json::{json, Value as JsonValue}; -use stream_assert::{assert_next_eq, assert_next_matches}; +use stream_assert::{assert_next_eq, assert_pending}; use tokio::{ spawn, time::{sleep, timeout}, @@ -87,42 +87,52 @@ async fn test_back_pagination() { }; join(paginate, observe_paginating).await; - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); - assert_let!(MessageType::Text(text) = msg.msgtype()); - assert_eq!(text.body, "hello world"); - - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); - assert_let!(MessageType::Text(text) = msg.msgtype()); - assert_eq!(text.body, "the world is big"); - - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::OtherState(state) = message.as_event().unwrap().content()); - assert_eq!(state.state_key(), ""); - assert_let!( - AnyOtherFullStateEventContent::RoomName(FullStateEventContent::Original { - content, - prev_content - }) = state.content() - ); - assert_eq!(content.name, "New room name"); - assert_eq!(prev_content.as_ref().unwrap().name.as_ref().unwrap(), "Old room name"); + // `m.room.name` + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::OtherState(state) = message.as_event().unwrap().content()); + assert_eq!(state.state_key(), ""); + assert_let!( + AnyOtherFullStateEventContent::RoomName(FullStateEventContent::Original { + content, + prev_content + }) = state.content() + ); + assert_eq!(content.name, "New room name"); + assert_eq!(prev_content.as_ref().unwrap().name.as_ref().unwrap(), "Old room name"); + } + + // `m.room.name` receives an update + { + assert_let!(Some(VectorDiff::Set { index, .. }) = timeline_stream.next().await); + assert_eq!(index, 0); + } + + // `m.room.message`: “the world is big” + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); + assert_let!(MessageType::Text(text) = msg.msgtype()); + assert_eq!(text.body, "the world is big"); + } + + // `m.room.message`: “hello world” + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); + assert_let!(MessageType::Text(text) = msg.msgtype()); + assert_eq!(text.body, "hello world"); + } + + // Date divider is updated. + { + assert_let!( + Some(VectorDiff::PushFront { value: date_divider }) = timeline_stream.next().await + ); + assert!(date_divider.is_date_divider()); + } - let date_divider = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert!(date_divider.is_date_divider()); + assert_pending!(timeline_stream); Mock::given(method("GET")) .and(path_regex(r"^/_matrix/client/r0/rooms/.*/messages$")) @@ -144,6 +154,8 @@ async fn test_back_pagination() { back_pagination_status, LiveBackPaginationStatus::Idle { hit_start_of_timeline: true } ); + + assert_pending!(timeline_stream); } #[async_test] @@ -212,27 +224,31 @@ async fn test_back_pagination_highlighted() { timeline.live_paginate_backwards(10).await.unwrap(); server.reset().await; - let first = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - let remote_event = first.as_event().unwrap(); - // Own events don't trigger push rules. - assert!(!remote_event.is_highlighted()); - - let second = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - let remote_event = second.as_event().unwrap(); - // `m.room.tombstone` should be highlighted by default. - assert!(remote_event.is_highlighted()); + // `m.room.tombstone` + { + assert_let!(Some(VectorDiff::PushBack { value: second }) = timeline_stream.next().await); + let remote_event = second.as_event().unwrap(); + // `m.room.tombstone` should be highlighted by default. + assert!(remote_event.is_highlighted()); + } + + // `m.room.message` + { + assert_let!(Some(VectorDiff::PushBack { value: first }) = timeline_stream.next().await); + let remote_event = first.as_event().unwrap(); + // Own events don't trigger push rules. + assert!(!remote_event.is_highlighted()); + } + + // Date divider + { + assert_let!( + Some(VectorDiff::PushFront { value: date_divider }) = timeline_stream.next().await + ); + assert!(date_divider.is_date_divider()); + } - let date_divider = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert!(date_divider.is_date_divider()); + assert_pending!(timeline_stream); } #[async_test] @@ -615,42 +631,52 @@ async fn test_empty_chunk() { }; join(paginate, observe_paginating).await; - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); - assert_let!(MessageType::Text(text) = msg.msgtype()); - assert_eq!(text.body, "hello world"); - - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); - assert_let!(MessageType::Text(text) = msg.msgtype()); - assert_eq!(text.body, "the world is big"); - - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::OtherState(state) = message.as_event().unwrap().content()); - assert_eq!(state.state_key(), ""); - assert_let!( - AnyOtherFullStateEventContent::RoomName(FullStateEventContent::Original { - content, - prev_content - }) = state.content() - ); - assert_eq!(content.name, "New room name"); - assert_eq!(prev_content.as_ref().unwrap().name.as_ref().unwrap(), "Old room name"); + // `m.room.name` + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::OtherState(state) = message.as_event().unwrap().content()); + assert_eq!(state.state_key(), ""); + assert_let!( + AnyOtherFullStateEventContent::RoomName(FullStateEventContent::Original { + content, + prev_content + }) = state.content() + ); + assert_eq!(content.name, "New room name"); + assert_eq!(prev_content.as_ref().unwrap().name.as_ref().unwrap(), "Old room name"); + } + + // `m.room.name` is updated + { + assert_let!(Some(VectorDiff::Set { index, .. }) = timeline_stream.next().await); + assert_eq!(index, 0); + } + + // `m.room.message`: “the world is big” + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); + assert_let!(MessageType::Text(text) = msg.msgtype()); + assert_eq!(text.body, "the world is big"); + } + + // `m.room.name`: “hello world” + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); + assert_let!(MessageType::Text(text) = msg.msgtype()); + assert_eq!(text.body, "hello world"); + } + + // Date divider + { + assert_let!( + Some(VectorDiff::PushFront { value: date_divider }) = timeline_stream.next().await + ); + assert!(date_divider.is_date_divider()); + } - let date_divider = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert!(date_divider.is_date_divider()); + assert_pending!(timeline_stream); } #[async_test] @@ -715,59 +741,65 @@ async fn test_until_num_items_with_empty_chunk() { }; join(paginate, observe_paginating).await; - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); - assert_let!(MessageType::Text(text) = msg.msgtype()); - assert_eq!(text.body, "hello world"); - - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); - assert_let!(MessageType::Text(text) = msg.msgtype()); - assert_eq!(text.body, "the world is big"); - - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::OtherState(state) = message.as_event().unwrap().content()); - assert_eq!(state.state_key(), ""); - assert_let!( - AnyOtherFullStateEventContent::RoomName(FullStateEventContent::Original { - content, - prev_content - }) = state.content() - ); - assert_eq!(content.name, "New room name"); - assert_eq!(prev_content.as_ref().unwrap().name.as_ref().unwrap(), "Old room name"); - - let date_divider = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert!(date_divider.is_date_divider()); + // `m.room.name` + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::OtherState(state) = message.as_event().unwrap().content()); + assert_eq!(state.state_key(), ""); + assert_let!( + AnyOtherFullStateEventContent::RoomName(FullStateEventContent::Original { + content, + prev_content + }) = state.content() + ); + assert_eq!(content.name, "New room name"); + assert_eq!(prev_content.as_ref().unwrap().name.as_ref().unwrap(), "Old room name"); + } + + // `m.room.name` is updated + { + assert_let!(Some(VectorDiff::Set { index, .. }) = timeline_stream.next().await); + assert_eq!(index, 0); + } + + // `m.room.message`: “the world is big” + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); + assert_let!(MessageType::Text(text) = msg.msgtype()); + assert_eq!(text.body, "the world is big"); + } + + // `m.room.name`: “hello world” + { + assert_let!(Some(VectorDiff::PushBack { value: message }) = timeline_stream.next().await); + assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); + assert_let!(MessageType::Text(text) = msg.msgtype()); + assert_eq!(text.body, "hello world"); + } + + // Date divider + { + assert_let!( + Some(VectorDiff::PushFront { value: date_divider }) = timeline_stream.next().await + ); + assert!(date_divider.is_date_divider()); + } timeline.live_paginate_backwards(10).await.unwrap(); - let message = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); - assert_let!(MessageType::Text(text) = msg.msgtype()); - assert_eq!(text.body, "hello room then"); + // `m.room.name`: “hello room then” + { + assert_let!( + Some(VectorDiff::Insert { index, value: message }) = timeline_stream.next().await + ); + assert_eq!(index, 1); + assert_let!(TimelineItemContent::Message(msg) = message.as_event().unwrap().content()); + assert_let!(MessageType::Text(text) = msg.msgtype()); + assert_eq!(text.body, "hello room then"); + } - let date_divider = assert_next_matches!( - timeline_stream, - VectorDiff::PushFront { value } => value - ); - assert!(date_divider.is_date_divider()); - assert_next_matches!(timeline_stream, VectorDiff::Remove { index: 2 }); + assert_pending!(timeline_stream); } #[async_test] diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs b/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs index ae194ceecaf..9a1301acd90 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs @@ -409,9 +409,8 @@ async fn test_timeline_duplicated_events() -> Result<()> { assert_timeline_stream! { [timeline_stream] - update[3] "$x3:bar.org"; - update[1] "$x1:bar.org"; remove[1]; + update[2] "$x3:bar.org"; append "$x1:bar.org"; update[3] "$x1:bar.org"; append "$x4:bar.org"; diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs b/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs index 249037faa1b..61b0c3efe44 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs @@ -289,6 +289,8 @@ async fn test_timeline_is_reset_when_a_user_is_ignored_or_unignored() { server.reset().await; // Timeline receives events as before. + assert_next_matches!(timeline_stream, VectorDiff::Clear); // TODO: Remove `RoomEventCacheUpdate::Clear` as it creates double + // `VectorDiff::Clear`. assert_next_matches!(timeline_stream, VectorDiff::PushBack { value } => { assert_eq!(value.as_event().unwrap().event_id(), Some(fourth_event_id)); }); diff --git a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs index 04d4a9774e1..499908eecd5 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs @@ -846,7 +846,7 @@ async fn test_delayed_invite_response_and_sent_message_decryption() -> Result<() let bob_sync_service = SyncService::builder(bob.clone()).build().await.unwrap(); bob_sync_service.start().await; - // alice creates a room and invites bob. + // Alice creates a room and will invite Bob. let alice_room = alice .create_room(assign!(CreateRoomRequest::new(), { invite: vec![], @@ -887,20 +887,21 @@ async fn test_delayed_invite_response_and_sent_message_decryption() -> Result<() assert_eq!(bob_room.state(), RoomState::Joined); assert!(bob_room.is_encrypted().await.unwrap()); - let bob_timeline = bob_room.timeline_builder().build().await?; + let bob_timeline = bob_room.timeline().await?; let (_, timeline_stream) = bob_timeline.subscribe().await; pin_mut!(timeline_stream); - // Get previous events, including the sent message + // Get previous events, including the sent messages bob_timeline.paginate_backwards(3).await?; // Look for the sent message, which should not be an UTD event loop { - let diff = timeout(Duration::from_millis(100), timeline_stream.next()) + let diff = timeout(Duration::from_millis(300), timeline_stream.next()) .await .expect("Timed out. Neither an UTD nor the sent message were found") .unwrap(); - if let VectorDiff::PushFront { value } = diff { + + if let VectorDiff::PushBack { value } = diff { if let Some(content) = value.as_event().map(|e| e.content()) { if let Some(message) = content.as_message() { if message.body() == "hello world" { diff --git a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs index 70d11ddc8af..40dbe1b8ed5 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs @@ -442,6 +442,11 @@ async fn test_enabling_backups_retries_decryption() { .await .expect("We should be able to paginate the timeline to fetch the history"); + // Wait for the event cache and the timeline to do their job. + // Timeline triggers a pagination, that inserts events in the event cache, that + // then broadcasts new events into the timeline. All this is async. + sleep(Duration::from_millis(300)).await; + let item = timeline.item_by_event_id(&event_id).await.expect("The event should be in the timeline"); @@ -622,6 +627,11 @@ async fn test_room_keys_received_on_notification_client_trigger_redecryption() { .await .expect("We should be able to paginate the timeline to fetch the history"); + // Wait for the event cache and the timeline to do their job. + // Timeline triggers a pagination, that inserts events in the event cache, that + // then broadcasts new events into the timeline. All this is async. + sleep(Duration::from_millis(300)).await; + if let Some(timeline_item) = timeline.item_by_event_id(&event_id).await { item = Some(timeline_item); break;