@@ -435,6 +435,7 @@ async fn test_backpaginate_many_times_with_many_iterations() {
435
435
}
436
436
437
437
let mut num_iterations = 0 ;
438
+ let mut num_paginations = 0 ;
438
439
let mut global_events = Vec :: new ( ) ;
439
440
let mut global_reached_start = false ;
440
441
@@ -459,19 +460,29 @@ async fn test_backpaginate_many_times_with_many_iterations() {
459
460
// Then if I backpaginate in a loop,
460
461
let pagination = room_event_cache. pagination ( ) ;
461
462
while pagination. get_or_wait_for_token ( ) . await . is_some ( ) {
462
- let BackPaginationOutcome { reached_start, events } =
463
- pagination. run_backwards ( 20 , once) . await . unwrap ( ) ;
463
+ pagination
464
+ . run_backwards ( 20 , |outcome, timeline_has_been_reset| {
465
+ num_paginations += 1 ;
464
466
465
- if !global_reached_start {
466
- global_reached_start = reached_start;
467
- }
468
- global_events. extend ( events) ;
467
+ assert_matches ! ( timeline_has_been_reset, TimelineHasBeenResetWhilePaginating :: No ) ;
468
+
469
+ if !global_reached_start {
470
+ global_reached_start = outcome. reached_start ;
471
+ }
472
+
473
+ global_events. extend ( outcome. events ) ;
474
+
475
+ ready ( ControlFlow :: Break ( ( ) ) )
476
+ } )
477
+ . await
478
+ . unwrap ( ) ;
469
479
470
480
num_iterations += 1 ;
471
481
}
472
482
473
483
// I'll get all the previous events,
474
- assert_eq ! ( num_iterations, 2 ) ;
484
+ assert_eq ! ( num_iterations, 2 ) ; // in two iterations…
485
+ assert_eq ! ( num_paginations, 2 ) ; // … we get two paginations.
475
486
assert ! ( global_reached_start) ;
476
487
477
488
assert_event_matches_msg ( & global_events[ 0 ] , "world" ) ;
@@ -540,6 +551,7 @@ async fn test_backpaginate_many_times_with_one_iteration() {
540
551
}
541
552
542
553
let mut num_iterations = 0 ;
554
+ let mut num_paginations = 0 ;
543
555
let mut global_events = Vec :: new ( ) ;
544
556
let mut global_reached_start = false ;
545
557
@@ -565,7 +577,11 @@ async fn test_backpaginate_many_times_with_one_iteration() {
565
577
let pagination = room_event_cache. pagination ( ) ;
566
578
while pagination. get_or_wait_for_token ( ) . await . is_some ( ) {
567
579
pagination
568
- . run_backwards ( 20 , |outcome, _timeline_has_been_reset| {
580
+ . run_backwards ( 20 , |outcome, timeline_has_been_reset| {
581
+ num_paginations += 1 ;
582
+
583
+ assert_matches ! ( timeline_has_been_reset, TimelineHasBeenResetWhilePaginating :: No ) ;
584
+
569
585
if !global_reached_start {
570
586
global_reached_start = outcome. reached_start ;
571
587
}
@@ -585,7 +601,8 @@ async fn test_backpaginate_many_times_with_one_iteration() {
585
601
}
586
602
587
603
// I'll get all the previous events,
588
- assert_eq ! ( num_iterations, 1 ) ; // in one iteration!
604
+ assert_eq ! ( num_iterations, 1 ) ; // in one iteration…
605
+ assert_eq ! ( num_paginations, 2 ) ; // … we get two paginations!
589
606
assert ! ( global_reached_start) ;
590
607
591
608
assert_event_matches_msg ( & global_events[ 0 ] , "world" ) ;
0 commit comments