From ea93f0f5b2e6d68887e1276b1cb5c1a9f44a80cc Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 10 Jun 2024 09:54:13 +0200 Subject: [PATCH 1/3] Fix overflow --- ic-task-scheduler/src/retry.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ic-task-scheduler/src/retry.rs b/ic-task-scheduler/src/retry.rs index 09e00b01..5b20a330 100644 --- a/ic-task-scheduler/src/retry.rs +++ b/ic-task-scheduler/src/retry.rs @@ -49,7 +49,7 @@ impl RetryPolicy { match self { RetryPolicy::None => false, RetryPolicy::Infinite => true, - RetryPolicy::MaxRetries { retries: attempts } => *attempts + 1 > failed_attempts, + RetryPolicy::MaxRetries { retries: attempts } => *attempts >= failed_attempts, } } } @@ -329,4 +329,28 @@ pub mod test { assert_eq!((true, 34), retry_strategy.should_retry(1)); assert_eq!((false, 34), retry_strategy.should_retry(2)); } + + #[test] + fn retry_policy_hedge_cases() { + assert!(RetryPolicy::None.should_retry(0)); + assert!(!RetryPolicy::None.should_retry(1)); + assert!(!RetryPolicy::None.should_retry(u32::MAX)); + assert!(!RetryPolicy::None.should_retry(u32::MAX-1)); + + assert!(RetryPolicy::MaxRetries { retries: 0 }.should_retry(0)); + assert!(!RetryPolicy::MaxRetries { retries: 0 }.should_retry(1)); + assert!(!RetryPolicy::MaxRetries { retries: 0 }.should_retry(u32::MAX-1)); + assert!(!RetryPolicy::MaxRetries { retries: 0 }.should_retry(u32::MAX)); + + assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(0)); + assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(1)); + assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(u32::MAX-1)); + assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(u32::MAX)); + + assert!(RetryPolicy::Infinite.should_retry(0)); + assert!(RetryPolicy::Infinite.should_retry(1)); + assert!(RetryPolicy::Infinite.should_retry(u32::MAX)); + assert!(RetryPolicy::Infinite.should_retry(u32::MAX-1)); + + } } From 5f6b0d6501eacfa765f2a0fd29de51a5007989d4 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 10 Jun 2024 09:54:31 +0200 Subject: [PATCH 2/3] fmt --- ic-task-scheduler/src/retry.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ic-task-scheduler/src/retry.rs b/ic-task-scheduler/src/retry.rs index 5b20a330..89c9ea70 100644 --- a/ic-task-scheduler/src/retry.rs +++ b/ic-task-scheduler/src/retry.rs @@ -335,22 +335,21 @@ pub mod test { assert!(RetryPolicy::None.should_retry(0)); assert!(!RetryPolicy::None.should_retry(1)); assert!(!RetryPolicy::None.should_retry(u32::MAX)); - assert!(!RetryPolicy::None.should_retry(u32::MAX-1)); + assert!(!RetryPolicy::None.should_retry(u32::MAX - 1)); assert!(RetryPolicy::MaxRetries { retries: 0 }.should_retry(0)); assert!(!RetryPolicy::MaxRetries { retries: 0 }.should_retry(1)); - assert!(!RetryPolicy::MaxRetries { retries: 0 }.should_retry(u32::MAX-1)); + assert!(!RetryPolicy::MaxRetries { retries: 0 }.should_retry(u32::MAX - 1)); assert!(!RetryPolicy::MaxRetries { retries: 0 }.should_retry(u32::MAX)); assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(0)); assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(1)); - assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(u32::MAX-1)); + assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(u32::MAX - 1)); assert!(RetryPolicy::MaxRetries { retries: u32::MAX }.should_retry(u32::MAX)); - + assert!(RetryPolicy::Infinite.should_retry(0)); assert!(RetryPolicy::Infinite.should_retry(1)); assert!(RetryPolicy::Infinite.should_retry(u32::MAX)); - assert!(RetryPolicy::Infinite.should_retry(u32::MAX-1)); - + assert!(RetryPolicy::Infinite.should_retry(u32::MAX - 1)); } } From 7f77ffd1c28cadf255a5ab2d7a1b152ed42baeb1 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 10 Jun 2024 09:57:46 +0200 Subject: [PATCH 3/3] typo --- ic-task-scheduler/src/retry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ic-task-scheduler/src/retry.rs b/ic-task-scheduler/src/retry.rs index 89c9ea70..b6c46356 100644 --- a/ic-task-scheduler/src/retry.rs +++ b/ic-task-scheduler/src/retry.rs @@ -331,7 +331,7 @@ pub mod test { } #[test] - fn retry_policy_hedge_cases() { + fn retry_policy_edge_cases() { assert!(RetryPolicy::None.should_retry(0)); assert!(!RetryPolicy::None.should_retry(1)); assert!(!RetryPolicy::None.should_retry(u32::MAX));