From 93fd94662aa13d95a3b0deab9c9f7fa12c226ca8 Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Tue, 5 Jul 2022 14:46:16 -0400 Subject: [PATCH] fixup Signed-off-by: Richard Zak --- tokio-stream/tests/stream_panic.rs | 3 +-- tokio/Cargo.toml | 4 ++- tokio/tests/io_buf_reader.rs | 1 + tokio/tests/rt_basic.rs | 2 ++ tokio/tests/rt_metrics.rs | 2 +- tokio/tests/rt_threaded.rs | 42 ++---------------------------- tokio/tests/sync_mpsc.rs | 8 +++--- tokio/tests/task_local_set.rs | 10 +++++-- tokio/tests/test_clock.rs | 3 --- tokio/tests/time_pause.rs | 9 +++++-- tokio/tests/time_timeout.rs | 2 +- 11 files changed, 30 insertions(+), 56 deletions(-) diff --git a/tokio-stream/tests/stream_panic.rs b/tokio-stream/tests/stream_panic.rs index 8ff9ff59b5f..22c1c208001 100644 --- a/tokio-stream/tests/stream_panic.rs +++ b/tokio-stream/tests/stream_panic.rs @@ -1,6 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "time")] -#![cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery +#![cfg(all(feature = "time", not(target_os = "wasi")))] // Wasi does not support panic recovery use parking_lot::{const_mutex, Mutex}; use std::error::Error; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 5edd9a2f645..b9aa68c8f94 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -150,9 +150,11 @@ async-stream = "0.3" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] proptest = "1" -rand = "0.8.0" socket2 = "0.4" +[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies] +rand = "0.8.0" + [target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3.0" diff --git a/tokio/tests/io_buf_reader.rs b/tokio/tests/io_buf_reader.rs index 864bc023ab5..0d3f6bafc20 100644 --- a/tokio/tests/io_buf_reader.rs +++ b/tokio/tests/io_buf_reader.rs @@ -277,6 +277,7 @@ async fn maybe_pending_buf_read() { assert_eq!(v, []); } +// https://github.com/rust-lang/futures-rs/pull/1573#discussion_r281162309 #[tokio::test] async fn maybe_pending_seek() { struct MaybePendingSeek<'a> { diff --git a/tokio/tests/rt_basic.rs b/tokio/tests/rt_basic.rs index c3df1c1a859..73bafdc4d5c 100644 --- a/tokio/tests/rt_basic.rs +++ b/tokio/tests/rt_basic.rs @@ -315,6 +315,7 @@ mod unstable { } #[test] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn spawns_do_nothing() { use std::sync::Arc; @@ -343,6 +344,7 @@ mod unstable { } #[test] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn shutdown_all_concurrent_block_on() { const N: usize = 2; use std::sync::{mpsc, Arc}; diff --git a/tokio/tests/rt_metrics.rs b/tokio/tests/rt_metrics.rs index e86beb91421..3b8070533cf 100644 --- a/tokio/tests/rt_metrics.rs +++ b/tokio/tests/rt_metrics.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", tokio_unstable))] +#![cfg(all(feature = "full", tokio_unstable, not(target_os = "wasi")))] use tokio::runtime::Runtime; use tokio::time::{self, Duration}; diff --git a/tokio/tests/rt_threaded.rs b/tokio/tests/rt_threaded.rs index a79007d48bc..187cd557b37 100644 --- a/tokio/tests/rt_threaded.rs +++ b/tokio/tests/rt_threaded.rs @@ -1,17 +1,12 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] -#[cfg(not(target_os = "wasi"))] use tokio::io::{AsyncReadExt, AsyncWriteExt}; -#[cfg(not(target_os = "wasi"))] use tokio::net::{TcpListener, TcpStream}; use tokio::runtime; use tokio::sync::oneshot; -#[cfg(not(target_os = "wasi"))] -use tokio_test::assert_err; -use tokio_test::assert_ok; +use tokio_test::{assert_err, assert_ok}; -#[cfg(not(target_os = "wasi"))] use futures::future::poll_fn; use std::future::Future; use std::pin::Pin; @@ -29,7 +24,6 @@ macro_rules! cfg_metrics { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn single_thread() { // No panic when starting a runtime w/ a single thread @@ -39,10 +33,6 @@ fn single_thread() { .build(); } -#[cfg_attr( - target_os = "wasi", - ignore = "WASI: std::mpsc without thread parking not working" -)] #[test] fn many_oneshot_futures() { // used for notifying the main thread @@ -170,7 +160,6 @@ fn many_multishot_futures() { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn spawn_shutdown() { let rt = rt(); @@ -190,7 +179,6 @@ fn spawn_shutdown() { assert_err!(rx.try_recv()); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support bind async fn client_server(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -215,7 +203,6 @@ async fn client_server(tx: mpsc::Sender<()>) { tx.send(()).unwrap(); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn drop_threadpool_drops_futures() { for _ in 0..1_000 { @@ -272,7 +259,6 @@ fn drop_threadpool_drops_futures() { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn start_stop_callbacks_called() { use std::sync::atomic::{AtomicUsize, Ordering}; @@ -307,7 +293,6 @@ fn start_stop_callbacks_called() { assert!(before_stop.load(Ordering::Relaxed) > 0); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn blocking() { // used for notifying the main thread @@ -353,7 +338,6 @@ fn blocking() { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn multi_threadpool() { use tokio::sync::oneshot; @@ -382,7 +366,6 @@ fn multi_threadpool() { // // The test ensures that, when this happens, attempting to consume from a // channel yields occasionally even if there are values ready to receive. -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn coop_and_block_in_place() { let rt = tokio::runtime::Builder::new_multi_thread() @@ -433,7 +416,6 @@ fn coop_and_block_in_place() { } // Testing this does not panic -#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[test] fn max_blocking_threads() { let _rt = tokio::runtime::Builder::new_multi_thread() @@ -442,7 +424,6 @@ fn max_blocking_threads() { .unwrap(); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[test] #[should_panic] fn max_blocking_threads_set_to_zero() { @@ -452,7 +433,6 @@ fn max_blocking_threads_set_to_zero() { .unwrap(); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn hang_on_shutdown() { let (sync_tx, sync_rx) = std::sync::mpsc::channel::<()>(); @@ -521,19 +501,12 @@ fn wake_during_shutdown() { } } - #[cfg(not(target_os = "wasi"))] let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(1) .enable_all() .build() .unwrap(); - #[cfg(target_os = "wasi")] - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap(); - let (f1, f2) = MyFuture::new(); rt.spawn(f1); @@ -542,20 +515,17 @@ fn wake_during_shutdown() { rt.block_on(async { tokio::time::sleep(tokio::time::Duration::from_millis(20)).await }); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[should_panic] #[tokio::test] async fn test_block_in_place1() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::test(flavor = "multi_thread")] async fn test_block_in_place2() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[should_panic] #[tokio::main(flavor = "current_thread")] #[test] @@ -563,20 +533,12 @@ async fn test_block_in_place3() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::main] #[test] async fn test_block_in_place4() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] fn rt() -> runtime::Runtime { runtime::Runtime::new().unwrap() } - -#[cfg(target_os = "wasi")] -fn rt() -> runtime::Runtime { - use runtime::Builder; - Builder::new_current_thread().enable_all().build().unwrap() -} diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index f598db0889a..a1510f57d09 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -88,7 +88,7 @@ async fn reserve_disarm() { } #[tokio::test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads async fn send_recv_stream_with_buffer() { use tokio_stream::StreamExt; @@ -192,7 +192,7 @@ async fn async_send_recv_unbounded() { } #[tokio::test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads async fn send_recv_stream_unbounded() { use tokio_stream::StreamExt; @@ -453,7 +453,7 @@ fn unconsumed_messages_are_dropped() { } #[test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads fn blocking_recv() { let (tx, mut rx) = mpsc::channel::(1); @@ -478,7 +478,7 @@ async fn blocking_recv_async() { } #[test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads fn blocking_send() { let (tx, mut rx) = mpsc::channel::(1); diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs index 91dd998d09c..c2bb4848c56 100644 --- a/tokio/tests/task_local_set.rs +++ b/tokio/tests/task_local_set.rs @@ -369,7 +369,10 @@ fn with_timeout(timeout: Duration, f: impl FnOnce() + Send + 'static) { thread.join().expect("test thread should not panic!") } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] +#[cfg_attr( + target_os = "wasi", + ignore = "`unwrap()` in `with_timeout()` panics on Wasi" +)] #[test] fn drop_cancels_remote_tasks() { // This test reproduces issue #1885. @@ -392,7 +395,10 @@ fn drop_cancels_remote_tasks() { }); } -#[cfg(not(target_os = "wasi"))] +#[cfg_attr( + target_os = "wasi", + ignore = "FIXME: `task::spawn_local().await.unwrap()` panics on Wasi" +)] #[test] fn local_tasks_wake_join_all() { // This test reproduces issue #2460. diff --git a/tokio/tests/test_clock.rs b/tokio/tests/test_clock.rs index 6141c11b534..891636fdb28 100644 --- a/tokio/tests/test_clock.rs +++ b/tokio/tests/test_clock.rs @@ -28,7 +28,6 @@ async fn can_pause_after_resume() { assert!(Instant::now() - start < Duration::from_secs(21)); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn freezing_time_while_frozen_panics() { @@ -36,14 +35,12 @@ async fn freezing_time_while_frozen_panics() { time::pause(); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn advancing_time_when_time_is_not_frozen_panics() { time::advance(Duration::from_secs(1)).await; } -#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn resuming_time_when_not_frozen_panics() { diff --git a/tokio/tests/time_pause.rs b/tokio/tests/time_pause.rs index 30b752335b8..6251b4b829f 100644 --- a/tokio/tests/time_pause.rs +++ b/tokio/tests/time_pause.rs @@ -1,10 +1,13 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads +#![cfg(feature = "full")] use rand::SeedableRng; use rand::{rngs::StdRng, Rng}; use tokio::time::{self, Duration, Instant, Sleep}; -use tokio_test::{assert_elapsed, assert_err, assert_pending, assert_ready, assert_ready_eq, task}; +use tokio_test::{assert_elapsed, assert_pending, assert_ready, assert_ready_eq, task}; + +#[cfg(not(target_os = "wasi"))] +use tokio_test::assert_err; use std::{ future::Future, @@ -26,12 +29,14 @@ async fn pause_time_in_task() { t.await.unwrap(); } +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[should_panic] async fn pause_time_in_main_threads() { tokio::time::pause(); } +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn pause_time_in_spawn_threads() { let t = tokio::spawn(async { diff --git a/tokio/tests/time_timeout.rs b/tokio/tests/time_timeout.rs index 63ea5c90487..ec871cf62fe 100644 --- a/tokio/tests/time_timeout.rs +++ b/tokio/tests/time_timeout.rs @@ -17,7 +17,7 @@ async fn simultaneous_deadline_future_completion() { assert_ready_ok!(fut.poll()); } -#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads")] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: `fut.poll()` panics on Wasi")] #[tokio::test] async fn completed_future_past_deadline() { // Wrap it with a deadline