From 08b5ad94fd9d07437712c1eed7b264eb3e505941 Mon Sep 17 00:00:00 2001 From: Kevin Song <4605384+chipbuster@users.noreply.github.com> Date: Sat, 22 Jan 2022 05:54:04 -0600 Subject: [PATCH] ci: Fix aws::expiration_date_set_from_file race (#3484) * ci: Fix aws::expiration_date_set_from_file race While aws::expiration_date_set_from_file will almost-always work perfectly locally, it is theoretically possible for the thread running the test to be scheduled away betwen writing the file with timing information and then actually reading it, resulting in a shorter-than-expected time appearing in the module. This can also happen if the test triggers right at the very end of a second (e.g. at 10:45:47.999995). This appears to actually happen sometimes on heavily-loaded GitHub Actions runners. To fix this issue, we allow for up to a two-second delay between when the file is written and when the test actually fires (allowing "30m", "29m59s", and "29m58s" as possible values). * Fix typo --- src/modules/aws.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/modules/aws.rs b/src/modules/aws.rs index 97bbbac4..95e31f2f 100644 --- a/src/modules/aws.rs +++ b/src/modules/aws.rs @@ -554,14 +554,19 @@ expiration={} credentials_path.to_string_lossy().as_ref(), ) .collect(); - let expected = Some(format!( - "on {}", - Color::Yellow - .bold() - .paint("☁️ astronauts (ap-northeast-2) [30m]") - )); - assert_eq!(expected, actual); + // In principle, "30m" should be correct. However, bad luck in scheduling + // on shared runners may delay it. Allow for up to 2 seconds of delay. + let possible_values = ["30m", "29m59s", "29m58s"]; + let possible_values = possible_values.map(|duration| { + let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{}]", duration); + Some(format!( + "on {}", + Color::Yellow.bold().paint(segment_colored) + )) + }); + + assert!(possible_values.contains(&actual)); dir.close() }