use std::time::Duration;
use crate::Attempt;
use tick::Clock;
#[derive(Debug)]
pub struct CloneArgs {
pub(super) attempt: Attempt,
}
impl CloneArgs {
#[must_use]
pub fn attempt(&self) -> Attempt {
self.attempt
}
}
#[derive(Debug)]
pub struct RecoveryArgs<'a> {
pub(super) clock: &'a Clock,
pub(super) attempt: Attempt,
}
impl RecoveryArgs<'_> {
#[must_use]
pub fn clock(&self) -> &Clock {
self.clock
}
#[must_use]
pub fn attempt(&self) -> Attempt {
self.attempt
}
}
#[derive(Debug)]
pub struct OnExecuteArgs {
pub(super) attempt: Attempt,
pub(super) delay: Duration,
}
impl OnExecuteArgs {
#[must_use]
pub fn attempt(&self) -> Attempt {
self.attempt
}
#[must_use]
pub fn delay(&self) -> Duration {
self.delay
}
}
#[derive(Debug)]
pub struct HedgingDelayArgs {
pub(super) attempt: Attempt,
}
impl HedgingDelayArgs {
#[must_use]
pub fn attempt(&self) -> Attempt {
self.attempt
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn clone_args() {
let args = CloneArgs {
attempt: Attempt::new(2, true),
};
assert_eq!(args.attempt().index(), 2);
assert!(args.attempt().is_last());
}
#[test]
fn recovery_args() {
let clock = Clock::new_frozen();
let args = RecoveryArgs {
clock: &clock,
attempt: Attempt::new(1, false),
};
let _clock = args.clock();
assert_eq!(args.attempt().index(), 1);
assert!(!args.attempt().is_last());
}
#[test]
fn on_execute_args() {
let args = OnExecuteArgs {
attempt: Attempt::new(1, false),
delay: Duration::from_millis(200),
};
assert_eq!(args.attempt().index(), 1);
assert_eq!(args.delay(), Duration::from_millis(200));
}
#[test]
fn hedging_delay_args() {
let args = HedgingDelayArgs {
attempt: Attempt::new(1, false),
};
assert_eq!(args.attempt().index(), 1);
assert!(!args.attempt().is_last());
}
}