Skip to content

Commit 6e91e7d

Browse files
committed
Fix a flaky preview2 test
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.
1 parent c927662 commit 6e91e7d

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

crates/wasi/src/preview2/pipe.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,35 +282,33 @@ impl Subscribe for ClosedOutputStream {
282282
#[cfg(test)]
283283
mod test {
284284
use super::*;
285+
use std::time::Duration;
285286
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
286287

287288
// This is a gross way to handle CI running under qemu for non-x86 architectures.
288289
#[cfg(not(target_arch = "x86_64"))]
289290
const TEST_ITERATIONS: usize = 10;
290291

291-
// This is a gross way to handle CI running under qemu for non-x86 architectures.
292-
#[cfg(not(target_arch = "x86_64"))]
293-
const REASONABLE_DURATION: std::time::Duration = std::time::Duration::from_millis(200);
294-
295292
#[cfg(target_arch = "x86_64")]
296293
const TEST_ITERATIONS: usize = 100;
297294

298-
#[cfg(target_arch = "x86_64")]
299-
const REASONABLE_DURATION: std::time::Duration = std::time::Duration::from_millis(10);
300-
301295
async fn resolves_immediately<F, O>(fut: F) -> O
302296
where
303297
F: futures::Future<Output = O>,
304298
{
305-
tokio::time::timeout(REASONABLE_DURATION, fut)
299+
// The input `fut` should resolve immediately, but in case it
300+
// accidentally doesn't don't hang the test indefinitely. Provide a
301+
// generous timeout to account for CI sensitivity and various systems.
302+
tokio::time::timeout(Duration::from_secs(2), fut)
306303
.await
307304
.expect("operation timed out")
308305
}
309306

310-
// TODO: is there a way to get tokio to warp through timeouts when it knows nothing is
311-
// happening?
312307
async fn never_resolves<F: futures::Future>(fut: F) {
313-
tokio::time::timeout(REASONABLE_DURATION, fut)
308+
// The input `fut` should never resolve, so only give it a small window
309+
// of budget before we time out. If `fut` is actually resolved this
310+
// should show up as a flaky test.
311+
tokio::time::timeout(Duration::from_millis(10), fut)
314312
.await
315313
.err()
316314
.expect("operation should time out");

0 commit comments

Comments
 (0)