mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-30 03:53:45 -04:00
test(event-cache): move test_load_previous_chunk to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
@@ -144,6 +144,9 @@ pub trait EventCacheStoreIntegrationTests {
|
||||
/// chunk from the store.
|
||||
async fn test_load_last_chunk_with_a_cycle(&self);
|
||||
|
||||
/// Test loading the previous chunk in a linked chunk from the store.
|
||||
async fn test_load_previous_chunk(&self);
|
||||
|
||||
/// Test loading a linked chunk incrementally (chunk by chunk) from the
|
||||
/// store.
|
||||
async fn test_linked_chunk_incremental_loading(&self);
|
||||
@@ -480,6 +483,74 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
|
||||
self.load_last_chunk(linked_chunk_id).await.unwrap_err();
|
||||
}
|
||||
|
||||
async fn test_load_previous_chunk(&self) {
|
||||
let room_id = room_id!("!r0:matrix.org");
|
||||
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 =
|
||||
self.load_previous_chunk(linked_chunk_id, CId::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.
|
||||
{
|
||||
self.handle_linked_chunk_updates(
|
||||
linked_chunk_id,
|
||||
vec![Update::NewItemsChunk { previous: None, new: CId::new(42), next: None }],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let previous_chunk =
|
||||
self.load_previous_chunk(linked_chunk_id, CId::new(42)).await.unwrap();
|
||||
|
||||
assert!(previous_chunk.is_none());
|
||||
}
|
||||
|
||||
// Case #3: there are two chunks.
|
||||
{
|
||||
self.handle_linked_chunk_updates(
|
||||
linked_chunk_id,
|
||||
vec![
|
||||
// new chunk before the one that exists.
|
||||
Update::NewItemsChunk {
|
||||
previous: None,
|
||||
new: CId::new(7),
|
||||
next: Some(CId::new(42)),
|
||||
},
|
||||
Update::PushItems {
|
||||
at: Position::new(CId::new(7), 0),
|
||||
items: vec![event("brigand du jorat"), event("morbier")],
|
||||
},
|
||||
],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let previous_chunk =
|
||||
self.load_previous_chunk(linked_chunk_id, CId::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");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async fn test_linked_chunk_incremental_loading(&self) {
|
||||
let room_id = room_id!("!r0:matrix.org");
|
||||
let linked_chunk_id = LinkedChunkId::Room(room_id);
|
||||
@@ -1976,6 +2047,13 @@ macro_rules! event_cache_store_integration_tests {
|
||||
event_cache_store.test_load_last_chunk_with_a_cycle().await;
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_load_previous_chunk() {
|
||||
let event_cache_store =
|
||||
get_event_cache_store().await.unwrap().into_event_cache_store();
|
||||
event_cache_store.test_load_previous_chunk().await;
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_linked_chunk_incremental_loading() {
|
||||
let event_cache_store =
|
||||
|
||||
@@ -12,16 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use matrix_sdk_base::{
|
||||
event_cache::{
|
||||
Gap,
|
||||
store::{
|
||||
EventCacheStore,
|
||||
integration_tests::{check_test_event, make_test_event},
|
||||
},
|
||||
},
|
||||
linked_chunk::{ChunkContent, ChunkIdentifier, LinkedChunkId, Position, Update},
|
||||
event_cache::{Gap, store::EventCacheStore},
|
||||
linked_chunk::{ChunkIdentifier, LinkedChunkId, Update},
|
||||
};
|
||||
use matrix_sdk_test::DEFAULT_TEST_ROOM_ID;
|
||||
|
||||
@@ -53,59 +46,6 @@ pub async fn test_add_gap_chunk_and_delete_it_immediately(store: IndexeddbEventC
|
||||
assert_eq!(chunks.len(), 1);
|
||||
}
|
||||
|
||||
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`]
|
||||
///
|
||||
@@ -150,13 +90,6 @@ macro_rules! indexeddb_event_cache_store_integration_tests {
|
||||
)
|
||||
.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
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1633,16 +1633,13 @@ mod tests {
|
||||
use matrix_sdk_base::{
|
||||
event_cache::store::{
|
||||
EventCacheStore, EventCacheStoreError, IntoEventCacheStore,
|
||||
integration_tests::{
|
||||
EventCacheStoreIntegrationTests, check_test_event, make_test_event,
|
||||
},
|
||||
integration_tests::EventCacheStoreIntegrationTests,
|
||||
},
|
||||
event_cache_store_integration_tests, event_cache_store_integration_tests_time,
|
||||
linked_chunk::{ChunkContent, ChunkIdentifier, LinkedChunkId, Position, Update},
|
||||
linked_chunk::{ChunkIdentifier, LinkedChunkId, Update},
|
||||
};
|
||||
use matrix_sdk_test::{DEFAULT_TEST_ROOM_ID, async_test};
|
||||
use once_cell::sync::Lazy;
|
||||
use ruma::room_id;
|
||||
use tempfile::{TempDir, tempdir};
|
||||
|
||||
use super::SqliteEventCacheStore;
|
||||
@@ -1806,84 +1803,6 @@ mod tests {
|
||||
let chunks = store.load_all_chunks(linked_chunk_id).await.unwrap();
|
||||
assert!(chunks.is_empty());
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_load_previous_chunk() {
|
||||
let room_id = room_id!("!r0:matrix.org");
|
||||
let linked_chunk_id = LinkedChunkId::Room(room_id);
|
||||
let event = |msg: &str| make_test_event(room_id, msg);
|
||||
let store = get_event_cache_store().await.expect("creating cache store failed");
|
||||
|
||||
// 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.
|
||||
{
|
||||
store
|
||||
.handle_linked_chunk_updates(
|
||||
linked_chunk_id,
|
||||
vec![Update::NewItemsChunk {
|
||||
previous: None,
|
||||
new: ChunkIdentifier::new(42),
|
||||
next: None,
|
||||
}],
|
||||
)
|
||||
.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.
|
||||
{
|
||||
store
|
||||
.handle_linked_chunk_updates(
|
||||
linked_chunk_id,
|
||||
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")],
|
||||
},
|
||||
],
|
||||
)
|
||||
.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");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user