Skip to content

Commit ef7b773

Browse files
authored
test(aws): fix flaky tests expiration_date_set expiration_date_set_from_file (starship#5685)
* fix(aws): fix flaky test `expiration_date_set` * fix(aws): fix flaky test `expiration_date_set_from_file`
1 parent 2bb57cf commit ef7b773

File tree

1 file changed

+40
-47
lines changed

1 file changed

+40
-47
lines changed

src/modules/aws.rs

+40-47
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,21 @@ credential_process = /opt/bin/awscreds-retriever
703703
now_plus_half_hour.to_rfc3339_opts(SecondsFormat::Secs, true),
704704
)
705705
.collect();
706-
let expected = Some(format!(
707-
"on {}",
708-
Color::Yellow
709-
.bold()
710-
.paint("☁️ astronauts (ap-northeast-2) [30m] ")
711-
));
712-
713-
assert_eq!(expected, actual);
706+
707+
let possible_values = [
708+
"30m2s", "30m1s", "30m", "29m59s", "29m58s", "29m57s", "29m56s", "29m55s",
709+
];
710+
let possible_values = possible_values.map(|duration| {
711+
let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{duration}] ");
712+
Some(format!(
713+
"on {}",
714+
Color::Yellow.bold().paint(segment_colored)
715+
))
716+
});
717+
assert!(
718+
possible_values.contains(&actual),
719+
"time is not in range: {actual:?}"
720+
);
714721
});
715722
}
716723

@@ -743,46 +750,32 @@ aws_secret_access_key=dummy
743750
)
744751
.unwrap();
745752

746-
let actual = ModuleRenderer::new("aws")
747-
.env("AWS_PROFILE", "astronauts")
748-
.env("AWS_REGION", "ap-northeast-2")
749-
.env(
750-
"AWS_SHARED_CREDENTIALS_FILE",
751-
credentials_path.to_string_lossy().as_ref(),
752-
)
753-
.collect();
754-
755-
let actual_variant = ModuleRenderer::new("aws")
756-
.env("AWS_PROFILE", "astronauts")
757-
.env("AWS_REGION", "ap-northeast-2")
758-
.env(
759-
"AWS_CREDENTIALS_FILE",
760-
credentials_path.to_string_lossy().as_ref(),
761-
)
762-
.collect();
763-
764-
assert_eq!(
765-
actual, actual_variant,
766-
"both AWS_SHARED_CREDENTIALS_FILE and AWS_CREDENTIALS_FILE should work"
767-
);
768-
769-
// In principle, "30m" should be correct. However, bad luck in scheduling
770-
// on shared runners may delay it.
771-
let possible_values = [
772-
"30m2s", "30m1s", "30m", "29m59s", "29m58s", "29m57s", "29m56s", "29m55s",
773-
];
774-
let possible_values = possible_values.map(|duration| {
775-
let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{duration}] ");
776-
Some(format!(
777-
"on {}",
778-
Color::Yellow.bold().paint(segment_colored)
779-
))
753+
let credentials_env_vars = ["AWS_SHARED_CREDENTIALS_FILE", "AWS_CREDENTIALS_FILE"];
754+
credentials_env_vars.iter().for_each(|env_var| {
755+
let actual = ModuleRenderer::new("aws")
756+
.env("AWS_PROFILE", "astronauts")
757+
.env("AWS_REGION", "ap-northeast-2")
758+
.env(env_var, credentials_path.to_string_lossy().as_ref())
759+
.collect();
760+
761+
// In principle, "30m" should be correct. However, bad luck in scheduling
762+
// on shared runners may delay it.
763+
let possible_values = [
764+
"30m2s", "30m1s", "30m", "29m59s", "29m58s", "29m57s", "29m56s", "29m55s",
765+
];
766+
let possible_values = possible_values.map(|duration| {
767+
let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{duration}] ");
768+
Some(format!(
769+
"on {}",
770+
Color::Yellow.bold().paint(segment_colored)
771+
))
772+
});
773+
774+
assert!(
775+
possible_values.contains(&actual),
776+
"time is not in range: {actual:?}"
777+
);
780778
});
781-
782-
assert!(
783-
possible_values.contains(&actual),
784-
"time is not in range: {actual:?}"
785-
);
786779
});
787780

788781
dir.close()

0 commit comments

Comments
 (0)