@@ -413,6 +413,7 @@ fn enter_then_notify_error() {
413
413
414
414
mod retry_policy {
415
415
use super :: * ;
416
+ use rstest:: rstest;
416
417
417
418
use crate :: service_protocol:: messages:: SleepCommandMessage ;
418
419
use test_log:: test;
@@ -556,6 +557,73 @@ mod retry_policy {
556
557
) ;
557
558
}
558
559
560
+ #[ rstest]
561
+ #[ case( 0 , 0 ) ]
562
+ #[ case( 0 , 1 ) ]
563
+ #[ case( 1 , 2 ) ]
564
+ #[ case( 2 , 2 ) ]
565
+ #[ case( 2 , 1 ) ]
566
+ #[ case( 2 , 0 ) ]
567
+ #[ case( 99 , 100 ) ]
568
+ #[ test_log:: test]
569
+ fn should_stop_retrying_with_retry_count_and_max_attempts (
570
+ #[ case] retry_count_since_last_stored_entry : usize ,
571
+ #[ case] max_attempts : usize ,
572
+ ) {
573
+ test_should_stop_retrying (
574
+ retry_count_since_last_stored_entry as u32 ,
575
+ Duration :: from_secs ( 1 ) ,
576
+ Duration :: from_secs ( 1 ) ,
577
+ RetryPolicy :: Exponential {
578
+ initial_interval : Duration :: from_secs ( 1 ) ,
579
+ factor : 1.0 ,
580
+ max_attempts : Some ( max_attempts as u32 ) ,
581
+ max_duration : None ,
582
+ max_interval : None ,
583
+ } ,
584
+ ) ;
585
+ }
586
+
587
+ #[ rstest]
588
+ #[ case( 0 , 2 ) ]
589
+ #[ case( 1 , 3 ) ]
590
+ #[ case( 99 , 101 ) ]
591
+ #[ test_log:: test]
592
+ fn should_continue_retrying_with_retry_count_and_max_attempts (
593
+ #[ case] retry_count_since_last_stored_entry : usize ,
594
+ #[ case] max_attempts : usize ,
595
+ ) {
596
+ test_should_continue_retrying (
597
+ retry_count_since_last_stored_entry as u32 ,
598
+ Duration :: from_secs ( 0 ) ,
599
+ Duration :: from_secs ( 0 ) ,
600
+ RetryPolicy :: Exponential {
601
+ initial_interval : Duration :: from_secs ( 1 ) ,
602
+ factor : 1.0 ,
603
+ max_attempts : Some ( max_attempts as u32 ) ,
604
+ max_duration : None ,
605
+ max_interval : None ,
606
+ } ,
607
+ Some ( Duration :: from_secs ( 1 ) ) ,
608
+ ) ;
609
+ }
610
+
611
+ #[ test]
612
+ fn exit_with_retryable_error_retry_policy_duration ( ) {
613
+ test_should_stop_retrying (
614
+ 0 ,
615
+ Duration :: from_secs ( 0 ) ,
616
+ Duration :: from_secs ( 1 ) ,
617
+ RetryPolicy :: Exponential {
618
+ initial_interval : Duration :: from_secs ( 1 ) ,
619
+ factor : 1.0 ,
620
+ max_attempts : None ,
621
+ max_duration : Some ( Duration :: from_secs ( 1 ) ) ,
622
+ max_interval : None ,
623
+ } ,
624
+ ) ;
625
+ }
626
+
559
627
#[ test]
560
628
fn exit_with_retryable_error_retry_policy_none ( ) {
561
629
test_should_stop_retrying ( 0 , Duration :: ZERO , Duration :: ZERO , RetryPolicy :: None )
@@ -604,6 +672,38 @@ mod retry_policy {
604
672
) ;
605
673
}
606
674
675
+ #[ test]
676
+ fn exit_with_retryable_error_retry_policy_exhausted_max_attempts_0 ( ) {
677
+ test_should_stop_retrying (
678
+ 0 ,
679
+ Duration :: from_secs ( 1 ) ,
680
+ Duration :: from_secs ( 1 ) ,
681
+ RetryPolicy :: Exponential {
682
+ initial_interval : Duration :: from_secs ( 1 ) ,
683
+ factor : 1.0 ,
684
+ max_attempts : Some ( 0 ) ,
685
+ max_duration : None ,
686
+ max_interval : None ,
687
+ } ,
688
+ ) ;
689
+ }
690
+
691
+ #[ test]
692
+ fn exit_with_retryable_error_retry_policy_exhausted_max_attempts_1 ( ) {
693
+ test_should_stop_retrying (
694
+ 1 ,
695
+ Duration :: from_secs ( 1 ) ,
696
+ Duration :: from_secs ( 1 ) ,
697
+ RetryPolicy :: Exponential {
698
+ initial_interval : Duration :: from_secs ( 1 ) ,
699
+ factor : 1.0 ,
700
+ max_attempts : Some ( 0 ) ,
701
+ max_duration : None ,
702
+ max_interval : None ,
703
+ } ,
704
+ ) ;
705
+ }
706
+
607
707
#[ test]
608
708
fn retry_info_is_zero_when_entry_is_the_one_after_the_first_new_entry ( ) {
609
709
let mut output = VMTestCase :: new ( )
0 commit comments