@@ -428,11 +428,12 @@ async fn test_reset_while_backpaginating() {
428
428
JoinedRoomBuilder :: new ( room_id)
429
429
// Note to self: a timeline must have at least single event to be properly
430
430
// serialized.
431
- . add_timeline_event ( event_builder. make_sync_message_event (
431
+ . add_timeline_event ( event_builder. make_sync_message_event_with_id (
432
432
user_id ! ( "@a:b.c" ) ,
433
+ event_id ! ( "$from_first_sync" ) ,
433
434
RoomMessageEventContent :: text_plain ( "heyo" ) ,
434
435
) )
435
- . set_timeline_prev_batch ( "first_backpagination " . to_owned ( ) ) ,
436
+ . set_timeline_prev_batch ( "first_prev_batch_token " . to_owned ( ) ) ,
436
437
) ;
437
438
let response_body = sync_builder. build_json_sync_response ( ) ;
438
439
@@ -471,25 +472,27 @@ async fn test_reset_while_backpaginating() {
471
472
JoinedRoomBuilder :: new ( room_id)
472
473
// Note to self: a timeline must have at least single event to be properly
473
474
// serialized.
474
- . add_timeline_event ( event_builder. make_sync_message_event (
475
+ . add_timeline_event ( event_builder. make_sync_message_event_with_id (
475
476
user_id ! ( "@a:b.c" ) ,
477
+ event_id ! ( "$from_second_sync" ) ,
476
478
RoomMessageEventContent :: text_plain ( "heyo" ) ,
477
479
) )
478
- . set_timeline_prev_batch ( "second_backpagination " . to_owned ( ) )
480
+ . set_timeline_prev_batch ( "second_prev_batch_token_from_sync " . to_owned ( ) )
479
481
. set_timeline_limited ( ) ,
480
482
) ;
481
483
let sync_response_body = sync_builder. build_json_sync_response ( ) ;
482
484
483
485
// First back-pagination request:
484
- let chunk = non_sync_events ! ( event_builder, [ ( room_id, "$2 " : "lalala" ) ] ) ;
486
+ let chunk = non_sync_events ! ( event_builder, [ ( room_id, "$from_backpagination " : "lalala" ) ] ) ;
485
487
let response_json = json ! ( {
486
488
"chunk" : chunk,
487
489
"start" : "t392-516_47314_0_7_1_1_1_11444_1" ,
490
+ "end" : "second_prev_batch_token_from_backpagination"
488
491
} ) ;
489
492
Mock :: given ( method ( "GET" ) )
490
493
. and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/messages$" ) )
491
494
. and ( header ( "authorization" , "Bearer 1234" ) )
492
- . and ( query_param ( "from" , "first_backpagination " ) )
495
+ . and ( query_param ( "from" , "first_prev_batch_token " ) )
493
496
. respond_with (
494
497
ResponseTemplate :: new ( 200 )
495
498
. set_body_json ( response_json. clone ( ) )
@@ -506,22 +509,33 @@ async fn test_reset_while_backpaginating() {
506
509
507
510
let rec = room_event_cache. clone ( ) ;
508
511
let first_token_clone = first_token. clone ( ) ;
509
- let backpagination = spawn ( async move { rec. backpaginate ( 20 , first_token_clone) . await } ) ;
512
+ let backpagination = spawn ( async move {
513
+ let ret = rec. backpaginate ( 20 , first_token_clone) . await ;
514
+
515
+ ret
516
+ } ) ;
510
517
511
518
// Receive the sync response (which clears the timeline).
512
519
mock_sync ( & server, sync_response_body, None ) . await ;
513
520
client. sync_once ( Default :: default ( ) ) . await . unwrap ( ) ;
514
521
515
522
let outcome = backpagination. await . expect ( "join failed" ) . unwrap ( ) ;
516
523
517
- // Backpagination should be confused, and the operation should result in an
518
- // unknown token.
519
- assert_matches ! ( outcome, BackPaginationOutcome :: UnknownBackpaginationToken ) ;
524
+ // Backpagination should have been executed before the sync, despite the
525
+ // concurrency here. The backpagination should have acquired a write lock before
526
+ // the sync.
527
+ {
528
+ assert_let ! ( BackPaginationOutcome :: Success { events, reached_start } = outcome) ;
529
+ assert ! ( !reached_start) ;
530
+ assert_event_matches_msg ( & events[ 0 ] . clone ( ) . into ( ) , "lalala" ) ;
531
+ assert_eq ! ( events. len( ) , 1 ) ;
532
+ }
520
533
521
534
// Now if we retrieve the earliest token, it's not the one we had before.
535
+ // Even better, it's the one from the sync, NOT from the backpagination!
522
536
let second_token = room_event_cache. oldest_backpagination_token ( None ) . await . unwrap ( ) . unwrap ( ) ;
523
537
assert ! ( first_token. unwrap( ) != second_token) ;
524
- assert_eq ! ( second_token. 0 , "second_backpagination " ) ;
538
+ assert_eq ! ( second_token. 0 , "second_prev_batch_token_from_sync " ) ;
525
539
}
526
540
527
541
#[ async_test]
0 commit comments