diff --git a/app/src-tauri/src/aws/pricing.rs b/app/src-tauri/src/aws/pricing.rs index 80dcb3a..60de75d 100644 --- a/app/src-tauri/src/aws/pricing.rs +++ b/app/src-tauri/src/aws/pricing.rs @@ -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 { diff --git a/app/src-tauri/src/aws/pricing/tests.rs b/app/src-tauri/src/aws/pricing/tests.rs index f012a22..ad0bc82 100644 --- a/app/src-tauri/src/aws/pricing/tests.rs +++ b/app/src-tauri/src/aws/pricing/tests.rs @@ -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:: }; + assert_eq!(c.rates_with::(none(), "us-west-2", at(T0)).await, None); + // Within the back-off the client is not even built. + let r = c + .rates_with::( + 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); +}