use google_cloud_gax::{
backoff_policy::BackoffPolicy, exponential_backoff::ExponentialBackoffBuilder,
};
use std::time::Duration;
pub fn default() -> impl BackoffPolicy {
ExponentialBackoffBuilder::new()
.with_initial_delay(Duration::from_secs(1))
.with_maximum_delay(Duration::from_secs(60))
.with_scaling(2.0)
.build()
.expect("statically configured policy should succeed")
}
#[cfg(test)]
mod tests {
use super::*;
use google_cloud_gax::retry_state::RetryState;
#[test]
fn default() {
let policy = super::default();
let delay = policy.on_failure(&RetryState::new(true).set_attempt_count(1_u32));
assert!(
delay <= Duration::from_secs(1),
"{delay:?}, policy={policy:?}"
);
let delay = policy.on_failure(&RetryState::new(true).set_attempt_count(2_u32));
assert!(
delay <= Duration::from_secs(2),
"{delay:?}, policy={policy:?}"
);
}
}