Skip to content

Commit 8e80e02

Browse files
committed
Add test for matrix_sdk::room::Common::timeline()
The test is only run when the `sled_state_store` feature is enabled. This also changes the test_json::MORE_SYNC and test_json::MORE_SYNC_2 to not responsed with a limited timeline.
1 parent 9e7bee8 commit 8e80e02

File tree

2 files changed

+144
-2
lines changed

2 files changed

+144
-2
lines changed

crates/matrix-sdk-test/src/test_json/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ lazy_static! {
697697
}
698698
},
699699
],
700-
"limited": true,
700+
"limited": false,
701701
"prev_batch": "t392-516_47314_0_7_1_1_1_11444_1"
702702
},
703703
"unread_notifications": {
@@ -828,7 +828,7 @@ lazy_static! {
828828
}
829829
},
830830
],
831-
"limited": true,
831+
"limited": false,
832832
"prev_batch": "s526_47314_0_7_1_1_1_11444_2"
833833
},
834834
"unread_notifications": {

crates/matrix-sdk/src/client.rs

+142
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,7 @@ pub(crate) mod test {
23032303
use std::{collections::BTreeMap, convert::TryInto, io::Cursor, str::FromStr, time::Duration};
23042304

23052305
use matrix_sdk_base::media::{MediaFormat, MediaRequest, MediaThumbnailSize, MediaType};
2306+
use matrix_sdk_common::deserialized_responses::SyncRoomEvent;
23062307
use matrix_sdk_test::{test_json, EventBuilder, EventsJson};
23072308
use mockito::{mock, Matcher};
23082309
use ruma::{
@@ -3808,4 +3809,145 @@ pub(crate) mod test {
38083809

38093810
matches::assert_matches!(encryption_event, AnySyncStateEvent::RoomEncryption(_));
38103811
}
3812+
3813+
#[async_test]
3814+
async fn room_timeline() {
3815+
let client = logged_in_client().await;
3816+
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
3817+
3818+
let sync = mock("GET", Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()))
3819+
.with_status(200)
3820+
.with_body(test_json::SYNC.to_string())
3821+
.match_header("authorization", "Bearer 1234")
3822+
.create();
3823+
3824+
let _ = client.sync_once(sync_settings).await.unwrap();
3825+
sync.assert();
3826+
drop(sync);
3827+
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
3828+
let (forward_stream, backward_stream) = room.timeline().await.unwrap();
3829+
3830+
let sync_2 = mock(
3831+
"GET",
3832+
Matcher::Regex(
3833+
r"^/_matrix/client/r0/sync\?.*since=s526_47314_0_7_1_1_1_11444_1.*".to_string(),
3834+
),
3835+
)
3836+
.with_status(200)
3837+
.with_body(test_json::MORE_SYNC.to_string())
3838+
.match_header("authorization", "Bearer 1234")
3839+
.create();
3840+
3841+
let sync_3 = mock(
3842+
"GET",
3843+
Matcher::Regex(
3844+
r"^/_matrix/client/r0/sync\?.*since=s526_47314_0_7_1_1_1_11444_2.*".to_string(),
3845+
),
3846+
)
3847+
.with_status(200)
3848+
.with_body(test_json::MORE_SYNC_2.to_string())
3849+
.match_header("authorization", "Bearer 1234")
3850+
.create();
3851+
3852+
let mocked_messages = mock(
3853+
"GET",
3854+
Matcher::Regex(
3855+
r"^/_matrix/client/r0/rooms/.*/messages.*from=t392-516_47314_0_7_1_1_1_11444_1.*"
3856+
.to_string(),
3857+
),
3858+
)
3859+
.with_status(200)
3860+
.with_body(test_json::SYNC_ROOM_MESSAGES_BATCH_1.to_string())
3861+
.match_header("authorization", "Bearer 1234")
3862+
.create();
3863+
3864+
let mocked_messages_2 = mock(
3865+
"GET",
3866+
Matcher::Regex(
3867+
r"^/_matrix/client/r0/rooms/.*/messages.*from=t47409-4357353_219380_26003_2269.*"
3868+
.to_string(),
3869+
),
3870+
)
3871+
.with_status(200)
3872+
.with_body(test_json::SYNC_ROOM_MESSAGES_BATCH_2.to_string())
3873+
.match_header("authorization", "Bearer 1234")
3874+
.create();
3875+
3876+
assert_eq!(client.sync_token().await, Some("s526_47314_0_7_1_1_1_11444_1".to_string()));
3877+
let sync_settings = SyncSettings::new()
3878+
.timeout(Duration::from_millis(3000))
3879+
.token("s526_47314_0_7_1_1_1_11444_1");
3880+
let _ = client.sync_once(sync_settings).await.unwrap();
3881+
sync_2.assert();
3882+
let sync_settings = SyncSettings::new()
3883+
.timeout(Duration::from_millis(3000))
3884+
.token("s526_47314_0_7_1_1_1_11444_2");
3885+
let _ = client.sync_once(sync_settings).await.unwrap();
3886+
sync_3.assert();
3887+
3888+
let expected_events = vec![
3889+
"$152037280074GZeOm:localhost",
3890+
"$editevid:localhost",
3891+
"$151957878228ssqrJ:localhost",
3892+
"$15275046980maRLj:localhost",
3893+
"$15275047031IXQRi:localhost",
3894+
"$098237280074GZeOm:localhost",
3895+
"$152037280074GZeOm2:localhost",
3896+
"$editevid2:localhost",
3897+
"$151957878228ssqrJ2:localhost",
3898+
"$15275046980maRLj2:localhost",
3899+
"$15275047031IXQRi2:localhost",
3900+
"$098237280074GZeOm2:localhost",
3901+
];
3902+
3903+
use futures_util::StreamExt;
3904+
let forward_events =
3905+
forward_stream.take(expected_events.len()).collect::<Vec<SyncRoomEvent>>().await;
3906+
3907+
assert!(forward_events.into_iter().zip(expected_events.iter()).all(|(a, b)| &a
3908+
.event_id()
3909+
.unwrap()
3910+
.as_str()
3911+
== b));
3912+
3913+
let expected_events = vec![
3914+
"$152037280074GZeOm2:localhost",
3915+
"$editevid2:localhost",
3916+
"$151957878228ssqrJ2:localhost",
3917+
"$15275046980maRLj2:localhost",
3918+
"$15275047031IXQRi2:localhost",
3919+
"$098237280074GZeOm2:localhost",
3920+
"$152037280074GZeOm:localhost",
3921+
"$editevid:localhost",
3922+
"$151957878228ssqrJ:localhost",
3923+
"$15275046980maRLj:localhost",
3924+
"$15275047031IXQRi:localhost",
3925+
"$098237280074GZeOm:localhost",
3926+
"$1444812213350496Caaaf:example.com",
3927+
"$1444812213350496Cbbbf:example.com",
3928+
"$1444812213350496Ccccf:example.com",
3929+
"$1444812213350496Caaak:example.com",
3930+
"$1444812213350496Cbbbk:example.com",
3931+
"$1444812213350496Cccck:example.com",
3932+
];
3933+
3934+
let join_handle = tokio::spawn(async move {
3935+
let backward_events = backward_stream
3936+
.take(expected_events.len())
3937+
.collect::<Vec<crate::Result<SyncRoomEvent>>>()
3938+
.await;
3939+
3940+
assert!(backward_events.into_iter().zip(expected_events.iter()).all(|(a, b)| &a
3941+
.unwrap()
3942+
.event_id()
3943+
.unwrap()
3944+
.as_str()
3945+
== b));
3946+
});
3947+
3948+
join_handle.await.unwrap();
3949+
3950+
mocked_messages.assert();
3951+
mocked_messages_2.assert();
3952+
}
38113953
}

0 commit comments

Comments
 (0)