Skip to content

Commit 7d5b499

Browse files
Add tests for run retry (#50)
1 parent c09e270 commit 7d5b499

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ googletest = "0.11"
3535
test-log = { version = "0.2", default-features = false, features = ["trace", "color"] }
3636
assert2 = "0.3"
3737
prost-build = "0.13"
38+
rstest = "0.26.1"

src/tests/run.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ fn enter_then_notify_error() {
413413

414414
mod retry_policy {
415415
use super::*;
416+
use rstest::rstest;
416417

417418
use crate::service_protocol::messages::SleepCommandMessage;
418419
use test_log::test;
@@ -556,6 +557,73 @@ mod retry_policy {
556557
);
557558
}
558559

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+
559627
#[test]
560628
fn exit_with_retryable_error_retry_policy_none() {
561629
test_should_stop_retrying(0, Duration::ZERO, Duration::ZERO, RetryPolicy::None)
@@ -604,6 +672,38 @@ mod retry_policy {
604672
);
605673
}
606674

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+
607707
#[test]
608708
fn retry_info_is_zero_when_entry_is_the_one_after_the_first_new_entry() {
609709
let mut output = VMTestCase::new()

0 commit comments

Comments
 (0)