Skip to content

Commit

Permalink
Merge pull request #219 from bitfinity-network/EPROD-911_fix_schedule…
Browse files Browse the repository at this point in the history
…r_overflow

[Eprod 911] fix scheduler overflow
  • Loading branch information
ufoscout authored Jun 10, 2024
2 parents 567b544 + 7f77ffd commit 58c876a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ic-task-scheduler/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -329,4 +329,27 @@ 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_edge_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));
}
}

0 comments on commit 58c876a

Please sign in to comment.