Skip to content

Commit

Permalink
Fix a flaky preview2 test (bytecodealliance#7138)
Browse files Browse the repository at this point in the history
Found in CI for bytecodealliance#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.
  • Loading branch information
alexcrichton authored and eduardomourar committed Oct 4, 2023
1 parent b35f32d commit e6d23b3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions crates/wasi/src/preview2/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, O>(fut: F) -> O
where
F: futures::Future<Output = O>,
{
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<F: futures::Future>(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");
Expand Down

0 comments on commit e6d23b3

Please sign in to comment.