test(event-cache): move test_linked_chunk_replace_item to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
@@ -141,6 +141,9 @@ pub trait EventCacheStoreIntegrationTests {
|
||||
/// store.
|
||||
async fn test_linked_chunk_incremental_loading(&self);
|
||||
|
||||
/// Test replacing an item in a linked chunk.
|
||||
async fn test_linked_chunk_replace_item(&self);
|
||||
|
||||
/// Test that rebuilding a linked chunk from an empty store doesn't return
|
||||
/// anything.
|
||||
async fn test_rebuild_empty_linked_chunk(&self);
|
||||
@@ -541,6 +544,46 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
|
||||
}
|
||||
}
|
||||
|
||||
async fn test_linked_chunk_replace_item(&self) {
|
||||
let room_id = &DEFAULT_TEST_ROOM_ID;
|
||||
let linked_chunk_id = LinkedChunkId::Room(room_id);
|
||||
let event_id = event_id!("$world");
|
||||
|
||||
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_with_event_id(room_id, "world", Some(event_id)),
|
||||
],
|
||||
},
|
||||
Update::ReplaceItem {
|
||||
at: Position::new(CId::new(42), 1),
|
||||
item: make_test_event_with_event_id(room_id, "yolo", Some(event_id)),
|
||||
},
|
||||
],
|
||||
)
|
||||
.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(), 2);
|
||||
check_test_event(&events[0], "hello");
|
||||
check_test_event(&events[1], "yolo");
|
||||
});
|
||||
}
|
||||
|
||||
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, _, _>(
|
||||
@@ -1306,6 +1349,13 @@ macro_rules! event_cache_store_integration_tests {
|
||||
event_cache_store.test_linked_chunk_incremental_loading().await;
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_replace_item() {
|
||||
let event_cache_store =
|
||||
get_event_cache_store().await.unwrap().into_event_cache_store();
|
||||
event_cache_store.test_linked_chunk_replace_item().await;
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_rebuild_empty_linked_chunk() {
|
||||
let event_cache_store =
|
||||
|
||||
@@ -133,36 +133,6 @@ pub async fn test_linked_chunk_new_gap_chunk(store: IndexeddbEventCacheStore) {
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn test_linked_chunk_replace_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::ReplaceItem {
|
||||
at: Position::new(ChunkIdentifier::new(42), 1),
|
||||
item: make_test_event(room_id, "yolo"),
|
||||
},
|
||||
];
|
||||
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(), 2);
|
||||
check_test_event(&events[0], "hello");
|
||||
check_test_event(&events[1], "yolo");
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -610,12 +580,6 @@ macro_rules! indexeddb_event_cache_store_integration_tests {
|
||||
$crate::event_cache_store::integration_tests::test_linked_chunk_new_gap_chunk(store).await
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_replace_item() {
|
||||
let store = get_event_cache_store().await.expect("Failed to get event cache store");
|
||||
$crate::event_cache_store::integration_tests::test_linked_chunk_replace_item(store).await
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_remove_chunk() {
|
||||
let store = get_event_cache_store().await.expect("Failed to get event cache store");
|
||||
|
||||
@@ -1635,9 +1635,7 @@ mod tests {
|
||||
Gap,
|
||||
store::{
|
||||
EventCacheStore, EventCacheStoreError,
|
||||
integration_tests::{
|
||||
check_test_event, make_test_event, make_test_event_with_event_id,
|
||||
},
|
||||
integration_tests::{check_test_event, make_test_event},
|
||||
},
|
||||
},
|
||||
event_cache_store_integration_tests, event_cache_store_integration_tests_time,
|
||||
@@ -1645,7 +1643,7 @@ mod tests {
|
||||
};
|
||||
use matrix_sdk_test::{DEFAULT_TEST_ROOM_ID, async_test};
|
||||
use once_cell::sync::Lazy;
|
||||
use ruma::{event_id, room_id};
|
||||
use ruma::room_id;
|
||||
use tempfile::{TempDir, tempdir};
|
||||
|
||||
use super::SqliteEventCacheStore;
|
||||
@@ -1782,54 +1780,6 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_replace_item() {
|
||||
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);
|
||||
let event_id = event_id!("$world");
|
||||
|
||||
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_with_event_id(room_id, "world", Some(event_id)),
|
||||
],
|
||||
},
|
||||
Update::ReplaceItem {
|
||||
at: Position::new(ChunkIdentifier::new(42), 1),
|
||||
item: make_test_event_with_event_id(room_id, "yolo", Some(event_id)),
|
||||
},
|
||||
],
|
||||
)
|
||||
.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(), 2);
|
||||
check_test_event(&events[0], "hello");
|
||||
check_test_event(&events[1], "yolo");
|
||||
});
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_remove_chunk() {
|
||||
let store = get_event_cache_store().await.expect("creating cache store failed");
|
||||
|
||||
Reference in New Issue
Block a user