From cd1fbef0eab7ba54886bafa129a43bfeec843b3a Mon Sep 17 00:00:00 2001 From: Michael Goldenberg Date: Thu, 22 Jan 2026 11:54:33 -0500 Subject: [PATCH] test(event-cache): copy test_linked_chunk_remove_chunk to integration tests Signed-off-by: Michael Goldenberg --- .../event_cache/store/integration_tests.rs | 63 +++++++++++++++++++ .../event_cache_store/integration_tests.rs | 53 ---------------- .../src/event_cache_store.rs | 61 +++--------------- 3 files changed, 71 insertions(+), 106 deletions(-) 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 4b3346888..c10459ed7 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 @@ -147,6 +147,9 @@ pub trait EventCacheStoreIntegrationTests { /// Test adding new gap chunk. async fn test_linked_chunk_new_gap_chunk(&self); + /// Test removing a chunk. + async fn test_linked_chunk_remove_chunk(&self); + /// Test replacing an item in a linked chunk. async fn test_linked_chunk_replace_item(&self); @@ -639,6 +642,59 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore { }); } + async fn test_linked_chunk_remove_chunk(&self) { + let room_id = &DEFAULT_TEST_ROOM_ID; + let linked_chunk_id = LinkedChunkId::Room(room_id); + + self.handle_linked_chunk_updates( + linked_chunk_id, + vec![ + Update::NewGapChunk { + previous: None, + new: CId::new(42), + next: None, + gap: Gap { prev_token: "raclette".to_owned() }, + }, + Update::NewGapChunk { + previous: Some(CId::new(42)), + new: CId::new(43), + next: None, + gap: Gap { prev_token: "fondue".to_owned() }, + }, + Update::NewGapChunk { + previous: Some(CId::new(43)), + new: CId::new(44), + next: None, + gap: Gap { prev_token: "tartiflette".to_owned() }, + }, + Update::RemoveChunk(CId::new(43)), + ], + ) + .await + .unwrap(); + + let mut chunks = self.load_all_chunks(linked_chunk_id).await.unwrap(); + + assert_eq!(chunks.len(), 2); + + // Chunks are ordered from smaller to bigger IDs. + let c = chunks.remove(0); + assert_eq!(c.identifier, CId::new(42)); + assert_eq!(c.previous, None); + assert_eq!(c.next, Some(CId::new(44))); + assert_matches!(c.content, ChunkContent::Gap(gap) => { + assert_eq!(gap.prev_token, "raclette"); + }); + + let c = chunks.remove(0); + assert_eq!(c.identifier, CId::new(44)); + assert_eq!(c.previous, Some(CId::new(42))); + assert_eq!(c.next, None); + assert_matches!(c.content, ChunkContent::Gap(gap) => { + assert_eq!(gap.prev_token, "tartiflette"); + }); + } + async fn test_linked_chunk_replace_item(&self) { let room_id = &DEFAULT_TEST_ROOM_ID; let linked_chunk_id = LinkedChunkId::Room(room_id); @@ -1458,6 +1514,13 @@ macro_rules! event_cache_store_integration_tests { event_cache_store.test_linked_chunk_new_gap_chunk().await; } + #[async_test] + async fn test_linked_chunk_remove_chunk() { + let event_cache_store = + get_event_cache_store().await.unwrap().into_event_cache_store(); + event_cache_store.test_linked_chunk_remove_chunk().await; + } + #[async_test] async fn test_linked_chunk_replace_item() { 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 5e315180d..f80d5ee4f 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,53 +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_remove_chunk(store: IndexeddbEventCacheStore) { - let room_id = &DEFAULT_TEST_ROOM_ID; - let linked_chunk_id = LinkedChunkId::Room(room_id); - let updates = vec![ - Update::NewGapChunk { - previous: None, - new: ChunkIdentifier::new(42), - next: None, - gap: Gap { prev_token: "raclette".to_owned() }, - }, - Update::NewGapChunk { - previous: Some(ChunkIdentifier::new(42)), - new: ChunkIdentifier::new(43), - next: None, - gap: Gap { prev_token: "fondue".to_owned() }, - }, - Update::NewGapChunk { - previous: Some(ChunkIdentifier::new(43)), - new: ChunkIdentifier::new(44), - next: None, - gap: Gap { prev_token: "tartiflette".to_owned() }, - }, - Update::RemoveChunk(ChunkIdentifier::new(43)), - ]; - 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(), 2); - - // Chunks are ordered from smaller to bigger IDs. - let c = chunks.remove(0); - assert_eq!(c.identifier, ChunkIdentifier::new(42)); - assert_eq!(c.previous, None); - assert_eq!(c.next, Some(ChunkIdentifier::new(44))); - assert_matches!(c.content, ChunkContent::Gap(gap) => { - assert_eq!(gap.prev_token, "raclette"); - }); - - let c = chunks.remove(0); - assert_eq!(c.identifier, ChunkIdentifier::new(44)); - assert_eq!(c.previous, Some(ChunkIdentifier::new(42))); - assert_eq!(c.next, None); - assert_matches!(c.content, ChunkContent::Gap(gap) => { - assert_eq!(gap.prev_token, "tartiflette"); - }); -} - pub async fn test_linked_chunk_push_items(store: IndexeddbEventCacheStore) { let room_id = &DEFAULT_TEST_ROOM_ID; let linked_chunk_id = LinkedChunkId::Room(room_id); @@ -492,12 +445,6 @@ macro_rules! indexeddb_event_cache_store_integration_tests { .await } - #[async_test] - async fn test_linked_chunk_remove_chunk() { - let store = get_event_cache_store().await.expect("Failed to get event cache store"); - $crate::event_cache_store::integration_tests::test_linked_chunk_remove_chunk(store).await - } - #[async_test] async fn test_linked_chunk_push_items() { 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 31dc1db11..122892b87 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -1634,8 +1634,10 @@ mod tests { event_cache::{ Gap, store::{ - EventCacheStore, EventCacheStoreError, - integration_tests::{check_test_event, make_test_event}, + EventCacheStore, EventCacheStoreError, IntoEventCacheStore, + integration_tests::{ + EventCacheStoreIntegrationTests, check_test_event, make_test_event, + }, }, }, event_cache_store_integration_tests, event_cache_store_integration_tests_time, @@ -1686,57 +1688,8 @@ mod tests { async fn test_linked_chunk_remove_chunk() { 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); - - store - .handle_linked_chunk_updates( - linked_chunk_id, - vec![ - Update::NewGapChunk { - previous: None, - new: ChunkIdentifier::new(42), - next: None, - gap: Gap { prev_token: "raclette".to_owned() }, - }, - Update::NewGapChunk { - previous: Some(ChunkIdentifier::new(42)), - new: ChunkIdentifier::new(43), - next: None, - gap: Gap { prev_token: "fondue".to_owned() }, - }, - Update::NewGapChunk { - previous: Some(ChunkIdentifier::new(43)), - new: ChunkIdentifier::new(44), - next: None, - gap: Gap { prev_token: "tartiflette".to_owned() }, - }, - Update::RemoveChunk(ChunkIdentifier::new(43)), - ], - ) - .await - .unwrap(); - - let mut chunks = store.load_all_chunks(linked_chunk_id).await.unwrap(); - - assert_eq!(chunks.len(), 2); - - // Chunks are ordered from smaller to bigger IDs. - let c = chunks.remove(0); - assert_eq!(c.identifier, ChunkIdentifier::new(42)); - assert_eq!(c.previous, None); - assert_eq!(c.next, Some(ChunkIdentifier::new(44))); - assert_matches!(c.content, ChunkContent::Gap(gap) => { - assert_eq!(gap.prev_token, "raclette"); - }); - - let c = chunks.remove(0); - assert_eq!(c.identifier, ChunkIdentifier::new(44)); - assert_eq!(c.previous, Some(ChunkIdentifier::new(42))); - assert_eq!(c.next, None); - assert_matches!(c.content, ChunkContent::Gap(gap) => { - assert_eq!(gap.prev_token, "tartiflette"); - }); + // Run corresponding integration test + store.clone().into_event_cache_store().test_linked_chunk_remove_chunk().await; // Check that cascading worked. Yes, SQLite, I doubt you. let gaps = store @@ -1756,6 +1709,8 @@ mod tests { .await .unwrap(); + // Check that the gaps match those set up in the corresponding integration test + // above assert_eq!(gaps, vec![42, 44]); }