From bdda880bae21da5ad56e53c1807ce3fb7f3dc344 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 4 Dec 2024 11:24:09 +0100 Subject: [PATCH] test: don't use the event cache storage but regular syncs instead --- .../tests/integration/timeline/edit.rs | 54 ++++------------ .../tests/integration/event_cache.rs | 63 +++++-------------- 2 files changed, 28 insertions(+), 89 deletions(-) diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs b/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs index 1d177c5e70f..4ad9e834238 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{sync::Arc, time::Duration}; +use std::time::Duration; use as_variant::as_variant; use assert_matches::assert_matches; @@ -20,16 +20,11 @@ use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::{FutureExt, StreamExt}; use matrix_sdk::{ - config::{StoreConfig, SyncSettings}, - linked_chunk::{ChunkIdentifier, Update}, + config::SyncSettings, room::edit::EditedContent, test_utils::{logged_in_client_with_server, mocks::MatrixMockServer}, Client, }; -use matrix_sdk_base::event_cache::{ - store::{EventCacheStore, MemoryStore}, - Gap, -}; use matrix_sdk_test::{ async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB, @@ -864,47 +859,20 @@ impl PendingEditHelper { async fn new() -> Self { let room_id = room_id!("!a98sd12bjh:example.org"); - let event_cache_store = Arc::new(MemoryStore::new()); let server = MatrixMockServer::new().await; + let client = server.client_builder().build().await; + + client.event_cache().subscribe().unwrap(); - let client = server - .client_builder() - .store_config( - StoreConfig::new("hodor".to_owned()).event_cache_store(event_cache_store.clone()), + // Fill the initial prev-batch token to avoid waiting for it later. + server + .sync_room( + &client, + JoinedRoomBuilder::new(room_id) + .set_timeline_prev_batch("prev-batch-token".to_owned()), ) - .build() .await; - { - // Fill the initial prev-batch token to avoid waiting for it later. - let ec = client.event_cache(); - ec.subscribe().unwrap(); - ec.enable_storage().unwrap(); - - event_cache_store - .handle_linked_chunk_updates( - room_id, - vec![ - // Maintain the invariant that the first chunk is an items. - Update::NewItemsChunk { - previous: None, - new: ChunkIdentifier::new(0), - next: None, - }, - // Mind the gap! - Update::NewGapChunk { - previous: Some(ChunkIdentifier::new(0)), - new: ChunkIdentifier::new(1), - next: None, - gap: Gap { prev_token: "prev-batch-token".to_owned() }, - }, - ], - ) - .await - .unwrap(); - } - - server.sync_joined_room(&client, room_id).await; server.mock_room_state_encryption().plain().mount().await; let room = client.get_room(room_id).unwrap(); diff --git a/crates/matrix-sdk/tests/integration/event_cache.rs b/crates/matrix-sdk/tests/integration/event_cache.rs index 861b1249375..8dced657e0e 100644 --- a/crates/matrix-sdk/tests/integration/event_cache.rs +++ b/crates/matrix-sdk/tests/integration/event_cache.rs @@ -1,16 +1,13 @@ -use std::{future::ready, ops::ControlFlow, sync::Arc, time::Duration}; +use std::{future::ready, ops::ControlFlow, time::Duration}; use assert_matches2::{assert_let, assert_matches}; use matrix_sdk::{ - config::StoreConfig, event_cache::{ paginator::PaginatorState, BackPaginationOutcome, EventCacheError, RoomEventCacheUpdate, TimelineHasBeenResetWhilePaginating, }, - linked_chunk::{ChunkIdentifier, Position, Update}, test_utils::{assert_event_matches_msg, logged_in_client_with_server, mocks::MatrixMockServer}, }; -use matrix_sdk_base::event_cache::store::{EventCacheStore, MemoryStore}; use matrix_sdk_test::{ async_test, event_factory::EventFactory, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, @@ -123,19 +120,10 @@ async fn test_event_cache_receives_events() { #[async_test] async fn test_ignored_unignored() { let server = MatrixMockServer::new().await; - - let event_cache_store = Arc::new(MemoryStore::new()); - let client = server - .client_builder() - .store_config( - StoreConfig::new("hodor".to_owned()).event_cache_store(event_cache_store.clone()), - ) - .build() - .await; + let client = server.client_builder().build().await; // Immediately subscribe the event cache to sync updates. client.event_cache().subscribe().unwrap(); - client.event_cache().enable_storage().unwrap(); let room_id = room_id!("!omelette:fromage.fr"); let other_room_id = room_id!("!galette:saucisse.bzh"); @@ -144,41 +132,24 @@ async fn test_ignored_unignored() { let ivan = user_id!("@ivan:lab.ch"); let f = EventFactory::new(); - // Given two rooms which add initial items, - event_cache_store - .handle_linked_chunk_updates( - room_id, - vec![ - Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None }, - Update::PushItems { - at: Position::new(ChunkIdentifier::new(0), 0), - items: vec![ - f.text_msg("hey there").sender(dexter).into_sync(), - f.text_msg("hoy!").sender(ivan).into_sync(), - ], - }, - ], + // Given two known rooms with initial items, + server + .sync_room( + &client, + JoinedRoomBuilder::new(room_id).add_timeline_bulk(vec![ + f.text_msg("hey there").sender(dexter).into_raw_sync(), + f.text_msg("hoy!").sender(ivan).into_raw_sync(), + ]), ) - .await - .unwrap(); + .await; - event_cache_store - .handle_linked_chunk_updates( - other_room_id, - vec![ - Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None }, - Update::PushItems { - at: Position::new(ChunkIdentifier::new(0), 0), - items: vec![f.text_msg("demat!").sender(ivan).into_sync()], - }, - ], + server + .sync_room( + &client, + JoinedRoomBuilder::new(other_room_id) + .add_timeline_bulk(vec![f.text_msg("demat!").sender(ivan).into_raw_sync()]), ) - .await - .unwrap(); - - // If I get informed about these two rooms during sync, - server.sync_joined_room(&client, room_id).await; - server.sync_joined_room(&client, other_room_id).await; + .await; // And subscribe to the room, let room = client.get_room(room_id).unwrap();