test(event-cache): copy test_linked_chunk_remove_chunk to integration tests

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
Michael Goldenberg
2026-01-22 11:54:33 -05:00
parent ca9c74d2c4
commit cd1fbef0ea
3 changed files with 71 additions and 106 deletions

View File

@@ -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 =

View File

@@ -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");

View File

@@ -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]);
}