diff --git a/crates/matrix-sdk-base/src/event_cache/store/integration_tests.rs b/crates/matrix-sdk-base/src/event_cache/store/integration_tests.rs index c3e6ea87c..5e54adf03 100644 --- a/crates/matrix-sdk-base/src/event_cache/store/integration_tests.rs +++ b/crates/matrix-sdk-base/src/event_cache/store/integration_tests.rs @@ -162,6 +162,9 @@ pub trait EventCacheStoreIntegrationTests { /// Test detaching last items from a linked chunk. async fn test_linked_chunk_detach_last_items(&self); + /// Test that start reattach and end reattach items does nothing. + async fn test_linked_chunk_start_end_reattach_items(&self); + /// Test that rebuilding a linked chunk from an empty store doesn't return /// anything. async fn test_rebuild_empty_linked_chunk(&self); @@ -864,6 +867,48 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore { }); } + async fn test_linked_chunk_start_end_reattach_items(&self) { + let room_id = *DEFAULT_TEST_ROOM_ID; + let linked_chunk_id = LinkedChunkId::Room(room_id); + + // Same updates and checks as test_linked_chunk_push_items, but with extra + // `StartReattachItems` and `EndReattachItems` updates, which must have no + // effects. + self.handle_linked_chunk_updates( + linked_chunk_id, + vec![ + Update::NewItemsChunk { previous: None, new: CId::new(42), next: None }, + Update::PushItems { + at: Position::new(CId::new(42), 0), + items: vec![ + make_test_event(room_id, "hello"), + make_test_event(room_id, "world"), + make_test_event(room_id, "howdy"), + ], + }, + Update::StartReattachItems, + Update::EndReattachItems, + ], + ) + .await + .unwrap(); + + let mut chunks = self.load_all_chunks(linked_chunk_id).await.unwrap(); + + assert_eq!(chunks.len(), 1); + + let c = chunks.remove(0); + assert_eq!(c.identifier, CId::new(42)); + assert_eq!(c.previous, None); + assert_eq!(c.next, None); + assert_matches!(c.content, ChunkContent::Items(events) => { + assert_eq!(events.len(), 3); + check_test_event(&events[0], "hello"); + check_test_event(&events[1], "world"); + check_test_event(&events[2], "howdy"); + }); + } + async fn test_rebuild_empty_linked_chunk(&self) { // When I rebuild a linked chunk from an empty store, it's empty. let linked_chunk = lazy_loader::from_all_chunks::<3, _, _>( @@ -1678,6 +1723,13 @@ macro_rules! event_cache_store_integration_tests { event_cache_store.test_linked_chunk_detach_last_items().await; } + #[async_test] + async fn test_linked_chunk_start_end_reattach_items() { + let event_cache_store = + get_event_cache_store().await.unwrap().into_event_cache_store(); + event_cache_store.test_linked_chunk_start_end_reattach_items().await; + } + #[async_test] async fn test_rebuild_empty_linked_chunk() { let event_cache_store = diff --git a/crates/matrix-sdk-indexeddb/src/event_cache_store/integration_tests.rs b/crates/matrix-sdk-indexeddb/src/event_cache_store/integration_tests.rs index 61e8eeb0a..5d7bbc600 100644 --- a/crates/matrix-sdk-indexeddb/src/event_cache_store/integration_tests.rs +++ b/crates/matrix-sdk-indexeddb/src/event_cache_store/integration_tests.rs @@ -57,42 +57,6 @@ pub async fn test_add_gap_chunk_and_delete_it_immediately(store: IndexeddbEventC assert_eq!(chunks.len(), 1); } -pub async fn test_linked_chunk_start_end_reattach_items(store: IndexeddbEventCacheStore) { - let room_id = &DEFAULT_TEST_ROOM_ID; - let linked_chunk_id = LinkedChunkId::Room(room_id); - // Same updates and checks as test_linked_chunk_push_items, but with extra - // `StartReattachItems` and `EndReattachItems` updates, which must have no - // effects. - let updates = vec![ - Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(42), next: None }, - Update::PushItems { - at: Position::new(ChunkIdentifier::new(42), 0), - items: vec![ - make_test_event(room_id, "hello"), - make_test_event(room_id, "world"), - make_test_event(room_id, "howdy"), - ], - }, - Update::StartReattachItems, - Update::EndReattachItems, - ]; - store.handle_linked_chunk_updates(linked_chunk_id, updates).await.unwrap(); - - let mut chunks = store.load_all_chunks(linked_chunk_id).await.unwrap(); - assert_eq!(chunks.len(), 1); - - let c = chunks.remove(0); - assert_eq!(c.identifier, ChunkIdentifier::new(42)); - assert_eq!(c.previous, None); - assert_eq!(c.next, None); - assert_matches!(c.content, ChunkContent::Items(events) => { - assert_eq!(events.len(), 3); - check_test_event(&events[0], "hello"); - check_test_event(&events[1], "world"); - check_test_event(&events[2], "howdy"); - }); -} - pub async fn test_linked_chunk_clear(store: IndexeddbEventCacheStore) { let room_id = &DEFAULT_TEST_ROOM_ID; let linked_chunk_id = LinkedChunkId::Room(room_id); @@ -358,13 +322,6 @@ macro_rules! indexeddb_event_cache_store_integration_tests { .await } - #[async_test] - async fn test_linked_chunk_start_end_reattach_items() { - let store = get_event_cache_store().await.expect("Failed to get event cache store"); - $crate::event_cache_store::integration_tests::test_linked_chunk_start_end_reattach_items(store) - .await - } - #[async_test] async fn test_linked_chunk_clear() { let store = get_event_cache_store().await.expect("Failed to get event cache store"); diff --git a/crates/matrix-sdk-sqlite/src/event_cache_store.rs b/crates/matrix-sdk-sqlite/src/event_cache_store.rs index 3a25f753e..43c561c3f 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -1741,56 +1741,6 @@ mod tests { assert_eq!(num_rows, 3); } - #[async_test] - async fn test_linked_chunk_start_end_reattach_items() { - let store = get_event_cache_store().await.expect("creating cache store failed"); - - let room_id = *DEFAULT_TEST_ROOM_ID; - let linked_chunk_id = LinkedChunkId::Room(room_id); - - // Same updates and checks as test_linked_chunk_push_items, but with extra - // `StartReattachItems` and `EndReattachItems` updates, which must have no - // effects. - store - .handle_linked_chunk_updates( - linked_chunk_id, - vec![ - Update::NewItemsChunk { - previous: None, - new: ChunkIdentifier::new(42), - next: None, - }, - Update::PushItems { - at: Position::new(ChunkIdentifier::new(42), 0), - items: vec![ - make_test_event(room_id, "hello"), - make_test_event(room_id, "world"), - make_test_event(room_id, "howdy"), - ], - }, - Update::StartReattachItems, - Update::EndReattachItems, - ], - ) - .await - .unwrap(); - - let mut chunks = store.load_all_chunks(linked_chunk_id).await.unwrap(); - - assert_eq!(chunks.len(), 1); - - let c = chunks.remove(0); - assert_eq!(c.identifier, ChunkIdentifier::new(42)); - assert_eq!(c.previous, None); - assert_eq!(c.next, None); - assert_matches!(c.content, ChunkContent::Items(events) => { - assert_eq!(events.len(), 3); - check_test_event(&events[0], "hello"); - check_test_event(&events[1], "world"); - check_test_event(&events[2], "howdy"); - }); - } - #[async_test] async fn test_linked_chunk_clear() { let store = get_event_cache_store().await.expect("creating cache store failed");