Lines
100 %
Functions
Branches
use super::*;
use crate::command::CmdError;
use crate::tag::lock::ATTEMPTS;
#[test]
fn retries_are_exhausted_after_the_attempt_budget() {
let mut tries = Tries::default();
for _ in 1..ATTEMPTS {
let step = tries.step::<(), ServerError>(Err(Attempt::Retry));
assert!(matches!(step, Ok(None)));
}
let last = tries.step::<(), ServerError>(Err(Attempt::Retry));
assert!(matches!(last, Err(ServerError::DB(DBError::WriteConflict))));
fn exhausted_command_tries_wrap_the_same_conflict() {
let last = (0..ATTEMPTS)
.map(|_| tries.step::<(), CmdError>(Err(Attempt::Retry)))
.last();
assert!(matches!(
last,
Some(Err(CmdError::Server(ServerError::DB(
DBError::WriteConflict
))))
));
fn a_commit_and_a_failure_end_the_loop() {
Tries::default().step::<_, CmdError>(Ok(7)),
Ok(Some(7))
let failed = Tries::default()
.step::<(), CmdError>(Err(Attempt::Failed(CmdError::Args("x".to_string()))));
assert!(matches!(failed, Err(CmdError::Args(_))));
fn a_changed_key_and_a_retryable_error_run_again() {
let changed = Attempt::<ServerError>::of::<(), ServerError>(
Ok::<_, ServerError>(Err(KeyChanged)),
|_| false,
|e| e,
);
assert!(matches!(changed, Err(Attempt::Retry)));
let retryable =
Attempt::<ServerError>::of::<(), ServerError>(Err(ServerError::Creation), |_| true, |e| e);
assert!(matches!(retryable, Err(Attempt::Retry)));
fn a_commit_and_another_error_end_the_attempt() {
let done = Attempt::<ServerError>::of::<(), ServerError>(
Ok::<_, ServerError>(Ok(())),
|_| true,
assert!(matches!(done, Ok(())));
let failed =
Attempt::<ServerError>::of::<(), ServerError>(Err(ServerError::Creation), |_| false, |e| e);
failed,
Err(Attempt::Failed(ServerError::Creation))