Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Zak <[email protected]>
  • Loading branch information
rjzak committed Jul 11, 2022
1 parent aeedf12 commit 4c0cf30
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 57 deletions.
6 changes: 5 additions & 1 deletion tests-integration/tests/macros_main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#![cfg(all(feature = "macros", feature = "rt-multi-thread"))]
#![cfg(all(
feature = "macros",
feature = "rt-multi-thread",
not(target_os = "wasi")
))]

#[tokio::main]
async fn basic_main() -> usize {
Expand Down
3 changes: 1 addition & 2 deletions tokio-stream/tests/stream_panic.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 3 additions & 1 deletion tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions tokio/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,11 @@ cfg_io_driver_impl! {
pub use driver::{Interest, Ready};
}

#[cfg_attr(target_os = "wasi", allow(unused_imports))]
mod poll_evented;

#[cfg(not(loom))]
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
pub(crate) use poll_evented::PollEvented;
}

Expand Down
1 change: 1 addition & 0 deletions tokio/src/runtime/blocking/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const KEEP_ALIVE: Duration = Duration::from_secs(10);
/// Tasks will be scheduled as non-mandatory, meaning they may not get executed
/// in case of runtime shutdown.
#[track_caller]
#[cfg_attr(target_os = "wasi", allow(dead_code))]
pub(crate) fn spawn_blocking<F, R>(func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
Expand Down
1 change: 1 addition & 0 deletions tokio/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ cfg_rt! {

mod blocking;
use blocking::BlockingPool;
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
pub(crate) use blocking::spawn_blocking;

cfg_trace! {
Expand Down
1 change: 1 addition & 0 deletions tokio/tests/io_buf_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 2 additions & 0 deletions tokio/tests/rt_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/rt_metrics.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
42 changes: 2 additions & 40 deletions tokio/tests/rt_threaded.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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 {
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -353,7 +338,6 @@ fn blocking() {
}
}

#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
#[test]
fn multi_threadpool() {
use tokio::sync::oneshot;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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() {
Expand All @@ -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::<()>();
Expand Down Expand Up @@ -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);
Expand All @@ -542,41 +515,30 @@ 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]
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()
}
8 changes: 4 additions & 4 deletions tokio/tests/sync_mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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::<u8>(1);

Expand All @@ -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::<u8>(1);

Expand Down
10 changes: 8 additions & 2 deletions tokio/tests/task_local_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions tokio/tests/test_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ 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() {
time::pause();
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() {
Expand Down
9 changes: 7 additions & 2 deletions tokio/tests/time_pause.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/time_timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c0cf30

Please sign in to comment.