@@ -293,14 +293,12 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
293293 )
294294 . await ?
295295 {
296- ExpireRefResult :: RefIsExpired => {
297- panic ! ( )
298- }
299296 ExpireRefResult :: NothingToDo => {
300297 panic ! ( )
301298 }
302- ExpireRefResult :: Done { released_snapshots, .. } => {
299+ ExpireRefResult :: Done { released_snapshots, ref_is_expired , .. } => {
303300 assert_eq ! ( released_snapshots. len( ) , 4 ) ;
301+ assert ! ( !ref_is_expired) ;
304302 }
305303 }
306304
@@ -332,9 +330,9 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
332330 )
333331 . await ?
334332 {
335- ExpireRefResult :: RefIsExpired => panic ! ( ) ,
336333 ExpireRefResult :: NothingToDo => panic ! ( ) ,
337- ExpireRefResult :: Done { released_snapshots, .. } => {
334+ ExpireRefResult :: Done { released_snapshots, ref_is_expired, .. } => {
335+ assert ! ( !ref_is_expired) ;
338336 assert_eq ! ( released_snapshots. len( ) , 4 ) ;
339337 }
340338 }
@@ -367,9 +365,9 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
367365 )
368366 . await ?
369367 {
370- ExpireRefResult :: RefIsExpired => panic ! ( ) ,
371368 ExpireRefResult :: NothingToDo => panic ! ( ) ,
372- ExpireRefResult :: Done { released_snapshots, .. } => {
369+ ExpireRefResult :: Done { released_snapshots, ref_is_expired, .. } => {
370+ assert ! ( !ref_is_expired) ;
373371 assert_eq ! ( released_snapshots. len( ) , 5 ) ;
374372 }
375373 }
@@ -402,9 +400,9 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
402400 )
403401 . await ?
404402 {
405- ExpireRefResult :: RefIsExpired => panic ! ( ) ,
406403 ExpireRefResult :: NothingToDo => panic ! ( ) ,
407- ExpireRefResult :: Done { released_snapshots, .. } => {
404+ ExpireRefResult :: Done { released_snapshots, ref_is_expired, .. } => {
405+ assert ! ( !ref_is_expired) ;
408406 assert_eq ! ( released_snapshots. len( ) , 5 ) ;
409407 }
410408 }
@@ -432,8 +430,8 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
432430}
433431
434432#[ tokio:: test]
435- pub async fn test_expire_ref_with_odd_timestamp ( ) -> Result < ( ) , Box < dyn std :: error :: Error > >
436- {
433+ pub async fn test_expire_ref_with_odd_timestamps ( )
434+ -> Result < ( ) , Box < dyn std :: error :: Error > > {
437435 let storage: Arc < dyn Storage + Send + Sync > = new_in_memory_storage ( ) . await ?;
438436 let storage_settings = storage. default_settings ( ) ;
439437 let repo = Repository :: create ( None , Arc :: clone ( & storage) , HashMap :: new ( ) ) . await ?;
@@ -489,15 +487,24 @@ pub async fn test_expire_ref_with_odd_timestamp() -> Result<(), Box<dyn std::err
489487 )
490488 . await ?
491489 {
492- ExpireRefResult :: RefIsExpired => { }
490+ ExpireRefResult :: Done { ref_is_expired, .. } => {
491+ assert ! ( ref_is_expired) ;
492+ // create another repo to avoid caching issues
493+ let repo =
494+ Repository :: open ( None , Arc :: clone ( & storage) , HashMap :: new ( ) ) . await ?;
495+ assert_eq ! (
496+ branch_commit_messages( & repo, "main" ) . await ,
497+ Vec :: from( [ "third" , "Repository initialized" ] )
498+ ) ;
499+ }
493500 _ => panic ! ( ) ,
494501 }
495502
496503 // create another repo to avoid caching issues
497504 let repo = Repository :: open ( None , Arc :: clone ( & storage) , HashMap :: new ( ) ) . await ?;
498505 assert_eq ! (
499506 branch_commit_messages( & repo, "main" ) . await ,
500- Vec :: from( [ "third" , "second" , "first" , " Repository initialized"] )
507+ Vec :: from( [ "third" , "Repository initialized" ] )
501508 ) ;
502509 Ok ( ( ) )
503510}
@@ -552,11 +559,11 @@ pub async fn test_expire_and_garbage_collect() -> Result<(), Box<dyn std::error:
552559 ) ;
553560 assert_eq ! (
554561 tag_commit_messages( & repo, "tag1" ) . await ,
555- Vec :: from( [ "3" , "2" , "1" , " Repository initialized"] )
562+ Vec :: from( [ "3" , "Repository initialized" ] )
556563 ) ;
557564 assert_eq ! (
558565 tag_commit_messages( & repo, "tag2" ) . await ,
559- Vec :: from( [ "5" , "4" , "2" , "1" , " Repository initialized"] )
566+ Vec :: from( [ "5" , "Repository initialized" ] )
560567 ) ;
561568
562569 let now = Utc :: now ( ) ;
@@ -575,10 +582,10 @@ pub async fn test_expire_and_garbage_collect() -> Result<(), Box<dyn std::error:
575582 )
576583 . await ?;
577584 // other expired snapshots are pointed by tags
578- assert_eq ! ( summary. snapshots_deleted, 2 ) ;
585+ assert_eq ! ( summary. snapshots_deleted, 5 ) ;
579586
580- // the non expired snapshots + the expired but pointed by tags snapshots
581- assert_eq ! ( storage. list_snapshots( & storage_settings) . await ?. count( ) . await , 13 ) ;
587+ // the non expired snapshots + the 2 expired but pointed by tags snapshots
588+ assert_eq ! ( storage. list_snapshots( & storage_settings) . await ?. count( ) . await , 10 ) ;
582589
583590 repo. delete_tag ( "tag1" ) . await ?;
584591
@@ -592,8 +599,8 @@ pub async fn test_expire_and_garbage_collect() -> Result<(), Box<dyn std::error:
592599 // other expired snapshots are pointed by tag2
593600 assert_eq ! ( summary. snapshots_deleted, 1 ) ;
594601
595- // the non expired snapshots + the expired but pointed by tags snapshots
596- assert_eq ! ( storage. list_snapshots( & storage_settings) . await ?. count( ) . await , 12 ) ;
602+ // the non expired snapshots + the 1 pointed by tag2 snapshots
603+ assert_eq ! ( storage. list_snapshots( & storage_settings) . await ?. count( ) . await , 9 ) ;
597604
598605 repo. delete_tag ( "tag2" ) . await ?;
599606
@@ -605,10 +612,61 @@ pub async fn test_expire_and_garbage_collect() -> Result<(), Box<dyn std::error:
605612 )
606613 . await ?;
607614 // tag2 snapshosts are released now
608- assert_eq ! ( summary. snapshots_deleted, 4 ) ;
615+ assert_eq ! ( summary. snapshots_deleted, 1 ) ;
609616
610617 // only the non expired snapshots left
611618 assert_eq ! ( storage. list_snapshots( & storage_settings) . await ?. count( ) . await , 8 ) ;
612619
613620 Ok ( ( ) )
614621}
622+
623+ #[ tokio:: test]
624+ /// In this test, we set up a repo as in the design document for expiration.
625+ ///
626+ /// We then, expire old snapshots and garbage collect. We verify we end up
627+ /// with what is expected according to the design document.
628+ pub async fn test_expire_and_garbage_collect_deliting_expired_refs ( )
629+ -> Result < ( ) , Box < dyn std:: error:: Error > > {
630+ let storage: Arc < dyn Storage + Send + Sync > = new_in_memory_storage ( ) . await ?;
631+ let storage_settings = storage. default_settings ( ) ;
632+ let mut repo = Repository :: create ( None , Arc :: clone ( & storage) , HashMap :: new ( ) ) . await ?;
633+
634+ let expire_older_than = make_design_doc_repo ( & mut repo) . await ?;
635+
636+ let asset_manager = Arc :: new ( AssetManager :: new_no_cache (
637+ storage. clone ( ) ,
638+ storage_settings. clone ( ) ,
639+ 1 ,
640+ ) ) ;
641+
642+ let result = expire (
643+ storage. as_ref ( ) ,
644+ & storage_settings,
645+ asset_manager. clone ( ) ,
646+ expire_older_than,
647+ // This is different compared to the previous test
648+ ExpiredRefAction :: Delete ,
649+ ExpiredRefAction :: Delete ,
650+ )
651+ . await ?;
652+
653+ assert_eq ! ( result. released_snapshots. len( ) , 7 ) ;
654+ assert_eq ! ( result. deleted_refs. len( ) , 2 ) ;
655+
656+ let now = Utc :: now ( ) ;
657+ let gc_config = GCConfig :: clean_all ( now, now, None ) ;
658+ let summary = garbage_collect (
659+ storage. as_ref ( ) ,
660+ & storage_settings,
661+ asset_manager. clone ( ) ,
662+ & gc_config,
663+ )
664+ . await ?;
665+
666+ assert_eq ! ( summary. snapshots_deleted, 7 ) ;
667+ assert_eq ! ( summary. transaction_logs_deleted, 7 ) ;
668+
669+ // only the non expired snapshots left
670+ assert_eq ! ( storage. list_snapshots( & storage_settings) . await ?. count( ) . await , 8 ) ;
671+ Ok ( ( ) )
672+ }
0 commit comments