Skip to content

Commit fc23044

Browse files
committed
add a unit test
Created using spr 1.3.6-beta.1
1 parent b0e129a commit fc23044

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ tufaceous-artifact.workspace = true
6060
camino-tempfile.workspace = true
6161
expectorate.workspace = true
6262
libc.workspace = true
63+
progenitor-extras.workspace = true
6364
proptest.workspace = true
6465
regress.workspace = true
6566
serde_urlencoded.workspace = true

common/src/backoff.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,47 @@ fn backon_builder() -> ::backon::ExponentialBuilder {
130130
.without_max_times()
131131
.with_jitter()
132132
}
133+
134+
#[cfg(test)]
135+
mod tests {
136+
use super::*;
137+
use http::{HeaderMap, StatusCode};
138+
use progenitor_extras::retry::{GoneCheckResult, retry_operation_while};
139+
use std::convert::Infallible;
140+
141+
/// Test that `backon_retry_policy_internal_service` does not limit retries.
142+
///
143+
/// We run a retry loop for 16384 attempts -- we assume that if it isn't
144+
/// limited for those many attempts, it isn't limited at all.
145+
#[tokio::test(start_paused = true)]
146+
async fn test_backon_retry_policy_internal_service() {
147+
let mut attempt = 0usize;
148+
let result = retry_operation_while(
149+
backon_retry_policy_internal_service(),
150+
|| {
151+
let a = attempt;
152+
attempt += 1;
153+
async move {
154+
if a < 16384 {
155+
Err(progenitor_client::Error::ErrorResponse(
156+
progenitor_client::ResponseValue::new(
157+
(),
158+
StatusCode::SERVICE_UNAVAILABLE,
159+
HeaderMap::new(),
160+
),
161+
))
162+
} else {
163+
Ok(())
164+
}
165+
}
166+
},
167+
|| async { Ok::<_, Infallible>(GoneCheckResult::StillAvailable) },
168+
|_| {},
169+
)
170+
.await;
171+
172+
result.expect("should succeed after 16384 retries");
173+
// 1 initial attempt + 16384 retries = 16385 total calls.
174+
assert_eq!(attempt, 16385);
175+
}
176+
}

0 commit comments

Comments
 (0)