test(event-cache): copy test_linked_chunk_remove_item to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
@@ -156,6 +156,9 @@ pub trait EventCacheStoreIntegrationTests {
|
||||
/// Test replacing an item in a linked chunk.
|
||||
async fn test_linked_chunk_replace_item(&self);
|
||||
|
||||
/// Test remove an item from a linked chunk.
|
||||
async fn test_linked_chunk_remove_item(&self);
|
||||
|
||||
/// Test that rebuilding a linked chunk from an empty store doesn't return
|
||||
/// anything.
|
||||
async fn test_rebuild_empty_linked_chunk(&self);
|
||||
@@ -779,6 +782,49 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
|
||||
});
|
||||
}
|
||||
|
||||
async fn test_linked_chunk_remove_item(&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::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, "one"),
|
||||
make_test_event(room_id, "two"),
|
||||
make_test_event(room_id, "three"),
|
||||
make_test_event(room_id, "four"),
|
||||
make_test_event(room_id, "five"),
|
||||
make_test_event(room_id, "six"),
|
||||
],
|
||||
},
|
||||
Update::RemoveItem { at: Position::new(CId::new(42), 2) /* "three" */ },
|
||||
],
|
||||
)
|
||||
.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(), 5);
|
||||
check_test_event(&events[0], "one");
|
||||
check_test_event(&events[1], "two");
|
||||
check_test_event(&events[2], "four");
|
||||
check_test_event(&events[3], "five");
|
||||
check_test_event(&events[4], "six");
|
||||
});
|
||||
}
|
||||
|
||||
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, _, _>(
|
||||
@@ -1579,6 +1625,13 @@ macro_rules! event_cache_store_integration_tests {
|
||||
event_cache_store.test_linked_chunk_replace_item().await;
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_remove_item() {
|
||||
let event_cache_store =
|
||||
get_event_cache_store().await.unwrap().into_event_cache_store();
|
||||
event_cache_store.test_linked_chunk_remove_item().await;
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_rebuild_empty_linked_chunk() {
|
||||
let event_cache_store =
|
||||
|
||||
@@ -57,32 +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_item(store: IndexeddbEventCacheStore) {
|
||||
let room_id = &DEFAULT_TEST_ROOM_ID;
|
||||
let linked_chunk_id = LinkedChunkId::Room(room_id);
|
||||
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")],
|
||||
},
|
||||
Update::RemoveItem { at: Position::new(ChunkIdentifier::new(42), 0) },
|
||||
];
|
||||
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(), 1);
|
||||
check_test_event(&events[0], "world");
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn test_linked_chunk_detach_last_items(store: IndexeddbEventCacheStore) {
|
||||
let room_id = &DEFAULT_TEST_ROOM_ID;
|
||||
let linked_chunk_id = LinkedChunkId::Room(room_id);
|
||||
@@ -414,12 +388,6 @@ macro_rules! indexeddb_event_cache_store_integration_tests {
|
||||
.await
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_remove_item() {
|
||||
let store = get_event_cache_store().await.expect("Failed to get event cache store");
|
||||
$crate::event_cache_store::integration_tests::test_linked_chunk_remove_item(store).await
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_detach_last_items() {
|
||||
let store = get_event_cache_store().await.expect("Failed to get event cache store");
|
||||
|
||||
@@ -1718,54 +1718,12 @@ mod tests {
|
||||
async fn test_linked_chunk_remove_item() {
|
||||
let store = get_event_cache_store().await.expect("creating cache store failed");
|
||||
|
||||
// Run corresponding integration test
|
||||
store.clone().into_event_cache_store().test_linked_chunk_remove_item().await;
|
||||
|
||||
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::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, "one"),
|
||||
make_test_event(room_id, "two"),
|
||||
make_test_event(room_id, "three"),
|
||||
make_test_event(room_id, "four"),
|
||||
make_test_event(room_id, "five"),
|
||||
make_test_event(room_id, "six"),
|
||||
],
|
||||
},
|
||||
Update::RemoveItem {
|
||||
at: Position::new(ChunkIdentifier::new(42), 2), /* "three" */
|
||||
},
|
||||
],
|
||||
)
|
||||
.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(), 5);
|
||||
check_test_event(&events[0], "one");
|
||||
check_test_event(&events[1], "two");
|
||||
check_test_event(&events[2], "four");
|
||||
check_test_event(&events[3], "five");
|
||||
check_test_event(&events[4], "six");
|
||||
});
|
||||
|
||||
// Make sure the position have been updated for the remaining events.
|
||||
let num_rows: u64 = store
|
||||
.read()
|
||||
|
||||
Reference in New Issue
Block a user