Skip to content

Commit bf37b0e

Browse files
committed
test(ui): Test long-polling in RoomListService.
This patch tests whether long-polling is used for Sliding Sync requests made by `RoomListService`.
1 parent b050681 commit bf37b0e

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

crates/matrix-sdk-ui/tests/integration/room_list_service.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ macro_rules! sync_then_assert_request_and_fake_response {
7373
[$server:ident, $room_list:ident, $stream:ident]
7474
$( states = $pre_state:pat => $post_state:pat, )?
7575
$( assert pos $pos:expr, )?
76+
$( assert timeout $timeout:expr, )?
7677
assert request $assert_request:tt { $( $request_json:tt )* },
7778
respond with = $( ( code $code:expr ) )? { $( $response_json:tt )* }
7879
$( , after delay = $response_delay:expr )?
@@ -83,6 +84,7 @@ macro_rules! sync_then_assert_request_and_fake_response {
8384
sync matches Some(Ok(_)),
8485
$( states = $pre_state => $post_state, )?
8586
$( assert pos $pos, )?
87+
$( assert timeout $timeout, )?
8688
assert request $assert_request { $( $request_json )* },
8789
respond with = $( ( code $code ) )? { $( $response_json )* },
8890
$( after delay = $response_delay, )?
@@ -94,6 +96,7 @@ macro_rules! sync_then_assert_request_and_fake_response {
9496
sync matches $sync_result:pat,
9597
$( states = $pre_state:pat => $post_state:pat, )?
9698
$( assert pos $pos:expr, )?
99+
$( assert timeout $timeout:expr, )?
97100
assert request $assert_request:tt { $( $request_json:tt )* },
98101
respond with = $( ( code $code:expr ) )? { $( $response_json:tt )* }
99102
$( , after delay = $response_delay:expr )?
@@ -112,6 +115,7 @@ macro_rules! sync_then_assert_request_and_fake_response {
112115
[$server, $stream]
113116
sync matches $sync_result,
114117
$( assert pos $pos, )?
118+
$( assert timeout $timeout, )?
115119
assert request $assert_request { $( $request_json )* },
116120
respond with = $( ( code $code ) )? { $( $response_json )* },
117121
$( after delay = $response_delay, )?
@@ -349,6 +353,10 @@ async fn test_sync_all_states() -> Result<(), Error> {
349353
sync_then_assert_request_and_fake_response! {
350354
[server, room_list, sync]
351355
states = Init => SettingUp,
356+
// No `pos` because it's the first fresh query.
357+
assert pos None,
358+
// No `timeout` because we don't want long-polling.
359+
assert timeout None,
352360
assert request = {
353361
"conn_id": "room-list",
354362
"lists": {
@@ -393,7 +401,7 @@ async fn test_sync_all_states() -> Result<(), Error> {
393401
"pos": "0",
394402
"lists": {
395403
ALL_ROOMS: {
396-
"count": 420,
404+
"count": 220,
397405
},
398406
},
399407
"rooms": {
@@ -406,6 +414,10 @@ async fn test_sync_all_states() -> Result<(), Error> {
406414
sync_then_assert_request_and_fake_response! {
407415
[server, room_list, sync]
408416
states = SettingUp => Running,
417+
// The previous `pos`.
418+
assert pos Some("0"),
419+
// Still no long-polling because the list isn't fully-loaded.
420+
assert timeout None,
409421
assert request = {
410422
"conn_id": "room-list",
411423
"lists": {
@@ -419,7 +431,7 @@ async fn test_sync_all_states() -> Result<(), Error> {
419431
"pos": "1",
420432
"lists": {
421433
ALL_ROOMS: {
422-
"count": 420,
434+
"count": 220,
423435
},
424436
},
425437
"rooms": {
@@ -431,6 +443,9 @@ async fn test_sync_all_states() -> Result<(), Error> {
431443
sync_then_assert_request_and_fake_response! {
432444
[server, room_list, sync]
433445
states = Running => Running,
446+
assert pos Some("1"),
447+
// Still no long-polling because the list isn't fully-loaded.
448+
assert timeout None,
434449
assert request = {
435450
"conn_id": "room-list",
436451
"lists": {
@@ -444,7 +459,7 @@ async fn test_sync_all_states() -> Result<(), Error> {
444459
"pos": "2",
445460
"lists": {
446461
ALL_ROOMS: {
447-
"count": 420,
462+
"count": 220,
448463
},
449464
},
450465
"rooms": {
@@ -456,11 +471,15 @@ async fn test_sync_all_states() -> Result<(), Error> {
456471
sync_then_assert_request_and_fake_response! {
457472
[server, room_list, sync]
458473
states = Running => Running,
474+
assert pos Some("2"),
475+
// Still no long-polling because the list isn't fully-loaded,
476+
// but it's about to be!
477+
assert timeout None,
459478
assert request = {
460479
"conn_id": "room-list",
461480
"lists": {
462481
ALL_ROOMS: {
463-
"ranges": [[0, 299]],
482+
"ranges": [[0, 219]],
464483
"timeline_limit": 1,
465484
},
466485
},
@@ -469,7 +488,7 @@ async fn test_sync_all_states() -> Result<(), Error> {
469488
"pos": "3",
470489
"lists": {
471490
ALL_ROOMS: {
472-
"count": 420,
491+
"count": 220,
473492
},
474493
},
475494
"rooms": {
@@ -481,11 +500,14 @@ async fn test_sync_all_states() -> Result<(), Error> {
481500
sync_then_assert_request_and_fake_response! {
482501
[server, room_list, sync]
483502
states = Running => Running,
503+
assert pos Some("3"),
504+
// The list is fully-loaded, we can start long-polling.
505+
assert timeout Some(30000),
484506
assert request = {
485507
"conn_id": "room-list",
486508
"lists": {
487509
ALL_ROOMS: {
488-
"ranges": [[0, 399]],
510+
"ranges": [[0, 219]],
489511
"timeline_limit": 1,
490512
},
491513
},
@@ -494,7 +516,7 @@ async fn test_sync_all_states() -> Result<(), Error> {
494516
"pos": "4",
495517
"lists": {
496518
ALL_ROOMS: {
497-
"count": 420,
519+
"count": 220,
498520
},
499521
},
500522
"rooms": {

crates/matrix-sdk-ui/tests/integration/sliding_sync.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ macro_rules! sliding_sync_then_assert_request_and_fake_response {
5959
(
6060
[$server:ident, $stream:ident]
6161
$( assert pos $pos:expr, )?
62+
$( assert timeout $timeout:expr, )?
6263
assert request $sign:tt { $( $request_json:tt )* },
6364
respond with = $( ( code $code:expr ) )? { $( $response_json:tt )* }
6465
$( , after delay = $response_delay:expr )?
@@ -68,6 +69,7 @@ macro_rules! sliding_sync_then_assert_request_and_fake_response {
6869
[$server, $stream]
6970
sync matches Some(Ok(_)),
7071
$( assert pos $pos, )?
72+
$( assert timeout $timeout, )?
7173
assert request $sign { $( $request_json )* },
7274
respond with = $( ( code $code ) )? { $( $response_json )* },
7375
$( after delay = $response_delay, )?
@@ -78,6 +80,7 @@ macro_rules! sliding_sync_then_assert_request_and_fake_response {
7880
[$server:ident, $stream:ident]
7981
sync matches $sync_result:pat,
8082
$( assert pos $pos:expr, )?
83+
$( assert timeout $timeout:expr, )?
8184
assert request $sign:tt { $( $request_json:tt )* },
8285
respond with = $( ( code $code:expr ) )? { $( $response_json:tt )* }
8386
$( , after delay = $response_delay:expr )?
@@ -124,8 +127,17 @@ macro_rules! sliding_sync_then_assert_request_and_fake_response {
124127
$(
125128
let pos: Option<&str> = $pos;
126129
match pos {
127-
Some(pos) => assert!(wiremock::matchers::query_param("pos", pos).matches(request)),
128-
None => assert!(wiremock::matchers::query_param_is_missing("pos").matches(request)),
130+
Some(pos) => assert!(wiremock::matchers::query_param("pos", pos).matches(request), "Invalid `pos` query parameter"),
131+
None => assert!(wiremock::matchers::query_param_is_missing("pos").matches(request), "Received an unexpected `pos` query parameter"),
132+
}
133+
)?
134+
135+
// Validate `timeout` from the query parameter if specified.
136+
$(
137+
let timeout: Option<usize> = $timeout;
138+
match timeout.map(|t| t.to_string()) {
139+
Some(timeout) => assert!(wiremock::matchers::query_param("timeout", timeout).matches(request), "Invalid `timeout` query parameter"),
140+
None => assert!(wiremock::matchers::query_param_is_missing("timeout").matches(request), "Received an unexpected `timeout` query parameter"),
129141
}
130142
)?
131143

0 commit comments

Comments
 (0)