fix(aws): no Pricing client counts as a failed fetch, so the 5-minute back-off applies
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be96b5f68f
commit
544409c554
2 files changed
+29
-2
No files matched your search
@@ -374,8 +374,14 @@ impl RatesCache {
|
||||
};
|
||||
let fetched = match tokio::time::timeout(FETCH_TIMEOUT, fetch).await {
|
||||
Ok(Some(r)) => r,
|
||||
// No client could be built: the stale cache answers.
|
||||
Ok(None) => return stale,
|
||||
// No client could be built: a failure like any other (building
|
||||
// one reads credentials, which can be slow), and the stale cache
|
||||
// answers.
|
||||
Ok(None) => {
|
||||
log::info!("No Fargate rates for {region}: no Pricing client could be built");
|
||||
self.note_failure(region, now, true);
|
||||
return stale;
|
||||
}
|
||||
Err(_) => Err(format!("timed out after {}s", FETCH_TIMEOUT.as_secs())),
|
||||
};
|
||||
match fetched {
|
||||
|
||||
@@ -395,3 +395,24 @@ async fn building_the_client_counts_against_the_same_timeout() {
|
||||
.await;
|
||||
assert_eq!(fresh, Some(RATES));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn no_client_counts_as_a_failure_and_is_not_asked_again_for_a_while() {
|
||||
let (_d, c) = cache();
|
||||
let none = || async { None::<FakeApi> };
|
||||
assert_eq!(c.rates_with::<FakeApi, FakeApi>(none(), "us-west-2", at(T0)).await, None);
|
||||
// Within the back-off the client is not even built.
|
||||
let r = c
|
||||
.rates_with::<FakeApi, FakeApi>(
|
||||
async { panic!("no client is built within the back-off") },
|
||||
"us-west-2",
|
||||
at(T0 + 60),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r, None);
|
||||
// After it, a working client is asked and clears the failure.
|
||||
let api = FakeApi::fixture();
|
||||
let later = T0 + RETRY_AFTER_FAILURE.as_secs();
|
||||
assert_eq!(c.rates(Some(&api), "us-west-2", at(later)).await, Some(RATES));
|
||||
assert_eq!(api.calls(), 1);
|
||||
}
|
||||
Reference in new issue
Block a user