Skip to content

Commit

Permalink
test: don't use the event cache storage but regular syncs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Dec 4, 2024
1 parent 1a63d8f commit e0b1b5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 89 deletions.
54 changes: 11 additions & 43 deletions crates/matrix-sdk-ui/tests/integration/timeline/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{sync::Arc, time::Duration};
use std::time::Duration;

use as_variant::as_variant;
use assert_matches::assert_matches;
use assert_matches2::assert_let;
use eyeball_im::VectorDiff;
use futures_util::{FutureExt, StreamExt};
use matrix_sdk::{
config::{StoreConfig, SyncSettings},
linked_chunk::{ChunkIdentifier, Update},
config::SyncSettings,
room::edit::EditedContent,
test_utils::{logged_in_client_with_server, mocks::MatrixMockServer},
Client,
};
use matrix_sdk_base::event_cache::{
store::{EventCacheStore, MemoryStore},
Gap,
};
use matrix_sdk_test::{
async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder,
SyncResponseBuilder, ALICE, BOB,
Expand Down Expand Up @@ -864,47 +859,20 @@ impl PendingEditHelper {
async fn new() -> Self {
let room_id = room_id!("!a98sd12bjh:example.org");

let event_cache_store = Arc::new(MemoryStore::new());
let server = MatrixMockServer::new().await;
let client = server.client_builder().build().await;

client.event_cache().subscribe().unwrap();

let client = server
.client_builder()
.store_config(
StoreConfig::new("hodor".to_owned()).event_cache_store(event_cache_store.clone()),
// Fill the initial prev-batch token to avoid waiting for it later.
server
.sync_room(
&client,
JoinedRoomBuilder::new(room_id)
.set_timeline_prev_batch("prev-batch-token".to_owned()),
)
.build()
.await;

{
// Fill the initial prev-batch token to avoid waiting for it later.
let ec = client.event_cache();
ec.subscribe().unwrap();
ec.enable_storage().unwrap();

event_cache_store
.handle_linked_chunk_updates(
room_id,
vec![
// Maintain the invariant that the first chunk is an items.
Update::NewItemsChunk {
previous: None,
new: ChunkIdentifier::new(0),
next: None,
},
// Mind the gap!
Update::NewGapChunk {
previous: Some(ChunkIdentifier::new(0)),
new: ChunkIdentifier::new(1),
next: None,
gap: Gap { prev_token: "prev-batch-token".to_owned() },
},
],
)
.await
.unwrap();
}

server.sync_joined_room(&client, room_id).await;
server.mock_room_state_encryption().plain().mount().await;

let room = client.get_room(room_id).unwrap();
Expand Down
63 changes: 17 additions & 46 deletions crates/matrix-sdk/tests/integration/event_cache.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::{future::ready, ops::ControlFlow, sync::Arc, time::Duration};
use std::{future::ready, ops::ControlFlow, time::Duration};

use assert_matches2::{assert_let, assert_matches};
use matrix_sdk::{
config::StoreConfig,
event_cache::{
paginator::PaginatorState, BackPaginationOutcome, EventCacheError, RoomEventCacheUpdate,
TimelineHasBeenResetWhilePaginating,
},
linked_chunk::{ChunkIdentifier, Position, Update},
test_utils::{assert_event_matches_msg, logged_in_client_with_server, mocks::MatrixMockServer},
};
use matrix_sdk_base::event_cache::store::{EventCacheStore, MemoryStore};
use matrix_sdk_test::{
async_test, event_factory::EventFactory, GlobalAccountDataTestEvent, JoinedRoomBuilder,
SyncResponseBuilder,
Expand Down Expand Up @@ -123,19 +120,10 @@ async fn test_event_cache_receives_events() {
#[async_test]
async fn test_ignored_unignored() {
let server = MatrixMockServer::new().await;

let event_cache_store = Arc::new(MemoryStore::new());
let client = server
.client_builder()
.store_config(
StoreConfig::new("hodor".to_owned()).event_cache_store(event_cache_store.clone()),
)
.build()
.await;
let client = server.client_builder().build().await;

// Immediately subscribe the event cache to sync updates.
client.event_cache().subscribe().unwrap();
client.event_cache().enable_storage().unwrap();

let room_id = room_id!("!omelette:fromage.fr");
let other_room_id = room_id!("!galette:saucisse.bzh");
Expand All @@ -144,41 +132,24 @@ async fn test_ignored_unignored() {
let ivan = user_id!("@ivan:lab.ch");
let f = EventFactory::new();

// Given two rooms which add initial items,
event_cache_store
.handle_linked_chunk_updates(
room_id,
vec![
Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None },
Update::PushItems {
at: Position::new(ChunkIdentifier::new(0), 0),
items: vec![
f.text_msg("hey there").sender(dexter).into_sync(),
f.text_msg("hoy!").sender(ivan).into_sync(),
],
},
],
// Given two known rooms with initial items,
server
.sync_room(
&client,
JoinedRoomBuilder::new(room_id).add_timeline_bulk(vec![
f.text_msg("hey there").sender(dexter).into_raw_sync(),
f.text_msg("hoy!").sender(ivan).into_raw_sync(),
]),
)
.await
.unwrap();
.await;

event_cache_store
.handle_linked_chunk_updates(
other_room_id,
vec![
Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None },
Update::PushItems {
at: Position::new(ChunkIdentifier::new(0), 0),
items: vec![f.text_msg("demat!").sender(ivan).into_sync()],
},
],
server
.sync_room(
&client,
JoinedRoomBuilder::new(other_room_id)
.add_timeline_bulk(vec![f.text_msg("demat!").sender(ivan).into_raw_sync()]),
)
.await
.unwrap();

// If I get informed about these two rooms during sync,
server.sync_joined_room(&client, room_id).await;
server.sync_joined_room(&client, other_room_id).await;
.await;

// And subscribe to the room,
let room = client.get_room(room_id).unwrap();
Expand Down

0 comments on commit e0b1b5d

Please sign in to comment.