From d5967ace4dbaff65a5316bdf5e991af9c2c95741 Mon Sep 17 00:00:00 2001 From: Daniel Parks Date: Fri, 7 Jul 2023 18:16:11 -0700 Subject: [PATCH] Prevent test_timeout from failing when a key is pressed `test_timeout()` checks that the timeout parameter works by waiting on stdout to be ready for reading with a timeout of 1 ms. One might guess that stdout would never be ready for reading, but it appears that on macOS, at least, pressing enter while running the tests will cause stdout to be ready for reading, which in turn will cause the test to fail. This switches `test_timeout()` to use `UnixStream::pair()` and just never write to the writer. This works even when keys are pressed while the tests are running. --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 73e693f..fe1d51b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -677,10 +677,12 @@ mod tests { #[test] fn test_timeout() -> io::Result<()> { + let (_writer, reader) = UnixStream::pair()?; + let mut events = Vec::new(); let mut sources = Sources::new(); - sources.register((), &io::stdout(), interest::READ); + sources.register((), &reader, interest::READ); let err = sources .poll(&mut events, Timeout::from_millis(1))