@@ -375,38 +375,42 @@ macro_rules! cryptostore_integration_tests {
375
375
376
376
#[ async_test]
377
377
async fn reset_inbound_group_session_for_backup( ) {
378
+ // Given a store exists where all sessions are backed up to backup_1
378
379
let ( account, store) =
379
380
get_loaded_store( "reset_inbound_group_session_for_backup" ) . await ;
380
- assert_eq!( store. inbound_group_session_counts( None ) . await . unwrap( ) . total, 0 ) ;
381
-
382
381
let room_id = & room_id!( "!test:localhost" ) ;
383
- let ( _ , session ) = account . create_group_session_pair_with_defaults ( room_id ) . await ;
384
-
385
- let changes =
386
- Changes { inbound_group_sessions : vec! [ session . clone ( ) ] , .. Default :: default ( ) } ;
387
-
382
+ let mut sessions : Vec < InboundGroupSession > = Vec :: with_capacity ( 10 ) ;
383
+ for _ in 0 .. 10 {
384
+ sessions . push ( account . create_group_session_pair_with_defaults ( room_id ) . await . 1 ) ;
385
+ }
386
+ let changes = Changes { inbound_group_sessions : sessions . clone ( ) , .. Default :: default ( ) } ;
388
387
store. save_changes( changes) . await . expect( "Can't save group session" ) ;
388
+ assert_eq!( store. inbound_group_sessions_for_backup( "backup_1" , 100 ) . await . unwrap( ) . len( ) , 10 ) ;
389
+ store. mark_inbound_group_sessions_as_backed_up(
390
+ "backup_1" ,
391
+ & ( 0 ..10 ) . map( |i| session_info( & sessions[ i] ) ) . collect:: <Vec <_>>( ) ,
392
+ ) . await . expect( "Failed to mark sessions as backed up" ) ;
389
393
390
- // Given we have backed up our session
391
- store
392
- . mark_inbound_group_sessions_as_backed_up( "bkpver1" , & [ session_info( & session) ] )
393
- . await
394
- . expect( "Failed to mark_inbound_group_sessions_as_backed_up." ) ;
395
-
396
- assert_eq!( store. inbound_group_session_counts( Some ( "bkpver1" ) ) . await . unwrap( ) . total, 1 ) ;
397
- assert_eq!( store. inbound_group_session_counts( Some ( "bkpver1" ) ) . await . unwrap( ) . backed_up, 1 ) ;
394
+ // Sanity: none need backing up to the same backup
395
+ {
396
+ let to_back_up_old = store. inbound_group_sessions_for_backup( "backup_1" , 10 ) . await . unwrap( ) ;
397
+ assert_eq!( to_back_up_old. len( ) , 0 ) ;
398
+ }
398
399
399
- // Sanity: before resetting, we have nothing to back up
400
- let to_back_up = store . inbound_group_sessions_for_backup ( "bkpver1" , 1 ) . await . unwrap ( ) ;
401
- assert_eq! ( to_back_up , vec! [ ] ) ;
400
+ // Some stores ignore backup_version and just reset when you tell them to. Tell
401
+ // them here.
402
+ store . reset_backup_state ( ) . await . expect ( "reset failed" ) ;
402
403
403
- // When we reset the backup
404
- store. reset_backup_state ( ) . await . unwrap( ) ;
404
+ // When we ask what needs backing up to a different backup version
405
+ let to_back_up = store. inbound_group_sessions_for_backup ( "backup_02" , 10 ) . await . unwrap( ) ;
405
406
406
- // Then after resetting, even if we supply the same backup version number, we need
407
- // to back up the session
408
- let to_back_up = store. inbound_group_sessions_for_backup( "bkpver1" , 1 ) . await . unwrap( ) ;
409
- assert_eq!( to_back_up, vec![ session] ) ;
407
+ // Then the answer is everything
408
+ let needs_backing_up = |i: usize | to_back_up. iter( ) . any( |s| s. session_id( ) == sessions[ i] . session_id( ) ) ;
409
+ assert!( needs_backing_up( 0 ) ) ;
410
+ assert!( needs_backing_up( 1 ) ) ;
411
+ assert!( needs_backing_up( 8 ) ) ;
412
+ assert!( needs_backing_up( 9 ) ) ;
413
+ assert_eq!( to_back_up. len( ) , 10 ) ;
410
414
}
411
415
412
416
#[ async_test]
0 commit comments