use core::time::Duration;
use relentless::prelude::*;
use relentless::{predicate, stop, wait};
const ARBITRARY_DURATION: Duration = Duration::from_millis(10);
#[test]
fn prelude_enables_wait_combinators() {
let _strategy = wait::exponential(ARBITRARY_DURATION)
.full_jitter()
.cap(Duration::from_secs(1));
}
#[test]
fn prelude_enables_stop_combinators() {
let _strategy = stop::attempts(3).or(stop::elapsed(Duration::from_secs(1)));
}
#[test]
fn prelude_enables_predicate_combinators() {
let pred = predicate::error(|e: &&str| *e == "boom").or(predicate::ok(|v: &u32| *v < 2));
assert!(pred.should_retry(&Err::<u32, &str>("boom")));
assert!(!pred.should_retry(&Err::<u32, &str>("fatal")));
assert!(pred.should_retry(&Ok::<u32, &str>(1)));
assert!(!pred.should_retry(&Ok::<u32, &str>(5)));
}
#[test]
fn prelude_enables_retry_ext() {
let result = (|| Ok::<u32, &str>(7)).retry().sleep(|_| {}).call();
assert_eq!(result.unwrap(), 7);
}