Skip to content

IndexedDB: Add IndexedDB implementation of LinkedChunk-related functions in EventCacheStore #5406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,59 @@ pub async fn test_load_last_chunk(store: IndexeddbEventCacheStore) {
assert_eq!(chunk_identifier_generator.current(), 42);
}

pub async fn test_load_previous_chunk(store: IndexeddbEventCacheStore) {
let room_id = &DEFAULT_TEST_ROOM_ID;
let linked_chunk_id = LinkedChunkId::Room(room_id);
let event = |msg: &str| make_test_event(room_id, msg);

// Case #1: no chunk at all, equivalent to having an nonexistent
// `before_chunk_identifier`.
let previous_chunk =
store.load_previous_chunk(linked_chunk_id, ChunkIdentifier::new(153)).await.unwrap();
assert!(previous_chunk.is_none());

// Case #2: there is one chunk only: we request the previous on this
// one, it doesn't exist.
let updates =
vec![Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(42), next: None }];
store.handle_linked_chunk_updates(linked_chunk_id, updates).await.unwrap();

let previous_chunk =
store.load_previous_chunk(linked_chunk_id, ChunkIdentifier::new(42)).await.unwrap();
assert!(previous_chunk.is_none());

// Case #3: there are two chunks.
let updates = vec![
// new chunk before the one that exists.
Update::NewItemsChunk {
previous: None,
new: ChunkIdentifier::new(7),
next: Some(ChunkIdentifier::new(42)),
},
Update::PushItems {
at: Position::new(ChunkIdentifier::new(7), 0),
items: vec![event("brigand du jorat"), event("morbier")],
},
];
store.handle_linked_chunk_updates(linked_chunk_id, updates).await.unwrap();

let previous_chunk =
store.load_previous_chunk(linked_chunk_id, ChunkIdentifier::new(42)).await.unwrap();

assert_matches!(previous_chunk, Some(previous_chunk) => {
assert_eq!(previous_chunk.identifier, 7);
assert!(previous_chunk.previous.is_none());
assert_matches!(previous_chunk.next, Some(next) => {
assert_eq!(next, 42);
});
assert_matches!(previous_chunk.content, ChunkContent::Items(items) => {
assert_eq!(items.len(), 2);
check_test_event(&items[0], "brigand du jorat");
check_test_event(&items[1], "morbier");
});
});
}

/// Macro for generating tests for IndexedDB implementation of
/// [`EventCacheStore`]
///
Expand Down Expand Up @@ -621,6 +674,13 @@ macro_rules! indexeddb_event_cache_store_integration_tests {
$crate::event_cache_store::integration_tests::test_load_last_chunk(store)
.await
}

#[async_test]
async fn test_load_previous_chunk() {
let store = get_event_cache_store().await.expect("Failed to get event cache store");
$crate::event_cache_store::integration_tests::test_load_previous_chunk(store)
.await
}
}
};
}
Expand Down Expand Up @@ -654,13 +714,34 @@ macro_rules! event_cache_store_integration_tests {
event_cache_store.test_handle_updates_and_rebuild_linked_chunk().await;
}

#[async_test]
async fn test_linked_chunk_incremental_loading() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_linked_chunk_incremental_loading().await;
}

#[async_test]
async fn test_rebuild_empty_linked_chunk() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_rebuild_empty_linked_chunk().await;
}

#[async_test]
async fn test_load_all_chunks_metadata() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_load_all_chunks_metadata().await;
}

#[async_test]
async fn test_clear_all_linked_chunks() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_clear_all_linked_chunks().await;
}

#[async_test]
async fn test_remove_room() {
let event_cache_store =
Expand Down
Loading
Loading