From e6d23b3b5af9fbedd7529ab1e5caaec09cb69015 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 3 Oct 2023 12:07:18 -0500 Subject: [PATCH] Fix a flaky preview2 test (#7138) Found in CI for #7099 this commit updates the durations used in the `resolves_immediately` and `never_resolves` tests. For immediately resolving it should be ok to wait for a generous amount of time since the timeout is only a protection against tests hanging. For `never_resolves` it should be ok to wait a short amount of time and any failure there will show up as a spurious failure. --- crates/wasi/src/preview2/pipe.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/crates/wasi/src/preview2/pipe.rs b/crates/wasi/src/preview2/pipe.rs index b99e68a28524..dae3e7569a99 100644 --- a/crates/wasi/src/preview2/pipe.rs +++ b/crates/wasi/src/preview2/pipe.rs @@ -282,35 +282,33 @@ impl Subscribe for ClosedOutputStream { #[cfg(test)] mod test { use super::*; + use std::time::Duration; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; // This is a gross way to handle CI running under qemu for non-x86 architectures. #[cfg(not(target_arch = "x86_64"))] const TEST_ITERATIONS: usize = 10; - // This is a gross way to handle CI running under qemu for non-x86 architectures. - #[cfg(not(target_arch = "x86_64"))] - const REASONABLE_DURATION: std::time::Duration = std::time::Duration::from_millis(200); - #[cfg(target_arch = "x86_64")] const TEST_ITERATIONS: usize = 100; - #[cfg(target_arch = "x86_64")] - const REASONABLE_DURATION: std::time::Duration = std::time::Duration::from_millis(10); - async fn resolves_immediately(fut: F) -> O where F: futures::Future, { - tokio::time::timeout(REASONABLE_DURATION, fut) + // The input `fut` should resolve immediately, but in case it + // accidentally doesn't don't hang the test indefinitely. Provide a + // generous timeout to account for CI sensitivity and various systems. + tokio::time::timeout(Duration::from_secs(2), fut) .await .expect("operation timed out") } - // TODO: is there a way to get tokio to warp through timeouts when it knows nothing is - // happening? async fn never_resolves(fut: F) { - tokio::time::timeout(REASONABLE_DURATION, fut) + // The input `fut` should never resolve, so only give it a small window + // of budget before we time out. If `fut` is actually resolved this + // should show up as a flaky test. + tokio::time::timeout(Duration::from_millis(10), fut) .await .err() .expect("operation should time out");