mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
wasm: initial support for wasm32-wasi target (#4716)
This adds initial, unstable, support for the wasm32-wasi target. Not all of Tokio's features are supported yet as WASI's non-blocking APIs are still limited. Refs: tokio-rs/tokio#4827
This commit is contained in:
@@ -489,9 +489,23 @@ jobs:
|
||||
- name: Install cargo-wasi
|
||||
run: cargo install cargo-wasi
|
||||
|
||||
# TODO: Expand this when full WASI support lands.
|
||||
# Currently, this is a bare bones regression test
|
||||
# for features that work today with wasi.
|
||||
- name: WASI test tokio full
|
||||
run: cargo test -p tokio --target wasm32-wasi --features full
|
||||
env:
|
||||
CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --"
|
||||
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
|
||||
|
||||
- name: WASI test tokio-util full
|
||||
run: cargo test -p tokio-util --target wasm32-wasi --features full
|
||||
env:
|
||||
CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --"
|
||||
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
|
||||
|
||||
- name: WASI test tokio-stream
|
||||
run: cargo test -p tokio-stream --target wasm32-wasi --features time,net,io-util,sync
|
||||
env:
|
||||
CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --"
|
||||
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
|
||||
|
||||
- name: test tests-integration --features wasi-rt
|
||||
# TODO: this should become: `cargo hack wasi test --each-feature`
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -4,6 +4,7 @@ use futures::channel::oneshot;
|
||||
use futures::executor::block_on;
|
||||
use std::thread;
|
||||
|
||||
#[cfg_attr(target_os = "wasi", ignore = "WASI: std::thread::spawn not supported")]
|
||||
#[test]
|
||||
fn join_with_select() {
|
||||
block_on(async {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))]
|
||||
|
||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
||||
use tokio::join;
|
||||
|
||||
@@ -38,6 +38,7 @@ parking_lot = "0.12.0"
|
||||
tokio-test = { path = "../tokio-test" }
|
||||
futures = { version = "0.3", default-features = false }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||
proptest = "1"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "time")]
|
||||
#![cfg(all(feature = "time", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
||||
|
||||
use parking_lot::{const_mutex, Mutex};
|
||||
use std::error::Error;
|
||||
|
||||
@@ -325,6 +325,7 @@ fn one_ready_many_none() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
proptest::proptest! {
|
||||
#[test]
|
||||
fn fuzz_pending_complete_mix(kinds: Vec<bool>) {
|
||||
|
||||
@@ -29,6 +29,7 @@ cfg_codec! {
|
||||
}
|
||||
|
||||
cfg_net! {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod udp;
|
||||
pub mod net;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#[cfg(tokio_unstable)]
|
||||
mod join_map;
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
mod spawn_pinned;
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
pub use spawn_pinned::LocalPoolHandle;
|
||||
|
||||
#[cfg(tokio_unstable)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![cfg(feature = "rt")]
|
||||
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use tokio::runtime::Builder;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![cfg(feature = "io-util")]
|
||||
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
|
||||
use std::error::Error;
|
||||
use std::io::{Cursor, Read, Result as IoResult};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
|
||||
|
||||
use parking_lot::{const_mutex, Mutex};
|
||||
use std::error::Error;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -778,6 +778,7 @@ async fn compact_change_deadline() {
|
||||
assert!(entry.is_none());
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")]
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn remove_after_compact() {
|
||||
let now = Instant::now();
|
||||
@@ -794,6 +795,7 @@ async fn remove_after_compact() {
|
||||
assert!(panic.is_err());
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")]
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn remove_after_compact_poll() {
|
||||
let now = Instant::now();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support UDP
|
||||
|
||||
use tokio::net::UdpSocket;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
+8
-5
@@ -51,7 +51,6 @@ net = [
|
||||
"mio/os-poll",
|
||||
"mio/os-ext",
|
||||
"mio/net",
|
||||
"socket2",
|
||||
"winapi/fileapi",
|
||||
"winapi/handleapi",
|
||||
"winapi/namedpipeapi",
|
||||
@@ -112,11 +111,13 @@ pin-project-lite = "0.2.0"
|
||||
bytes = { version = "1.0.0", optional = true }
|
||||
once_cell = { version = "1.5.2", optional = true }
|
||||
memchr = { version = "2.2", optional = true }
|
||||
mio = { version = "0.8.1", optional = true }
|
||||
socket2 = { version = "0.4.4", optional = true, features = [ "all" ] }
|
||||
mio = { version = "0.8.4", optional = true }
|
||||
num_cpus = { version = "1.8.0", optional = true }
|
||||
parking_lot = { version = "0.12.0", optional = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
socket2 = { version = "0.4.4", features = [ "all" ] }
|
||||
|
||||
# Currently unstable. The API exposed by these features may be broken at any time.
|
||||
# Requires `--cfg tokio_unstable` to enable.
|
||||
[target.'cfg(tokio_unstable)'.dependencies]
|
||||
@@ -149,10 +150,12 @@ async-stream = "0.3"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||
proptest = "1"
|
||||
rand = "0.8.0"
|
||||
socket2 = "0.4"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
[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"
|
||||
|
||||
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ cfg_coop! {
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
fn get() -> Budget {
|
||||
|
||||
@@ -72,6 +72,8 @@ pub(super) struct Inner {
|
||||
io_dispatch: RwLock<IoDispatcher>,
|
||||
|
||||
/// Used to wake up the reactor from a call to `turn`.
|
||||
/// Not supported on Wasi due to lack of threading support.
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
waker: mio::Waker,
|
||||
|
||||
metrics: IoDriverMetrics,
|
||||
@@ -115,6 +117,7 @@ impl Driver {
|
||||
/// creation.
|
||||
pub(crate) fn new() -> io::Result<Driver> {
|
||||
let poll = mio::Poll::new()?;
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
let waker = mio::Waker::new(poll.registry(), TOKEN_WAKEUP)?;
|
||||
let registry = poll.registry().try_clone()?;
|
||||
|
||||
@@ -129,6 +132,7 @@ impl Driver {
|
||||
inner: Arc::new(Inner {
|
||||
registry,
|
||||
io_dispatch: RwLock::new(IoDispatcher::new(allocator)),
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
waker,
|
||||
metrics: IoDriverMetrics::default(),
|
||||
}),
|
||||
@@ -164,6 +168,11 @@ impl Driver {
|
||||
match self.poll.poll(&mut events, max_wait) {
|
||||
Ok(_) => {}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
|
||||
#[cfg(target_os = "wasi")]
|
||||
Err(e) if e.kind() == io::ErrorKind::InvalidInput => {
|
||||
// In case of wasm32_wasi this error happens, when trying to poll without subscriptions
|
||||
// just return from the park, as there would be nothing, which wakes us up.
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
|
||||
@@ -300,6 +309,7 @@ impl Handle {
|
||||
/// blocked in `turn`, then the next call to `turn` will not block and
|
||||
/// return immediately.
|
||||
fn wakeup(&self) {
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
self.inner.waker.wake().expect("failed to wake I/O driver");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -393,6 +393,20 @@ compile_error! {
|
||||
"Tokio requires the platform pointer width to be 32, 64, or 128 bits"
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
not(tokio_unstable),
|
||||
target_arch = "wasm32",
|
||||
any(
|
||||
feature = "fs",
|
||||
feature = "io-std",
|
||||
feature = "net",
|
||||
feature = "process",
|
||||
feature = "rt-multi-thread",
|
||||
feature = "signal"
|
||||
)
|
||||
))]
|
||||
compile_error!("Only features sync,macros,io-util,rt are supported on wasm.");
|
||||
|
||||
// Includes re-exports used by macros.
|
||||
//
|
||||
// This module is not intended to be part of the public API. In general, any
|
||||
|
||||
+26
-3
@@ -61,6 +61,7 @@ macro_rules! cfg_fs {
|
||||
($($item:item)*) => {
|
||||
$(
|
||||
#[cfg(feature = "fs")]
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
|
||||
$item
|
||||
)*
|
||||
@@ -247,6 +248,7 @@ macro_rules! cfg_process {
|
||||
#[cfg(feature = "process")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "process")))]
|
||||
#[cfg(not(loom))]
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
$item
|
||||
)*
|
||||
}
|
||||
@@ -275,6 +277,7 @@ macro_rules! cfg_signal {
|
||||
#[cfg(feature = "signal")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
|
||||
#[cfg(not(loom))]
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
$item
|
||||
)*
|
||||
}
|
||||
@@ -334,7 +337,7 @@ macro_rules! cfg_not_rt {
|
||||
macro_rules! cfg_rt_multi_thread {
|
||||
($($item:item)*) => {
|
||||
$(
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
|
||||
$item
|
||||
)*
|
||||
@@ -451,7 +454,8 @@ macro_rules! cfg_has_atomic_u64 {
|
||||
target_arch = "arm",
|
||||
target_arch = "mips",
|
||||
target_arch = "powerpc",
|
||||
target_arch = "riscv32"
|
||||
target_arch = "riscv32",
|
||||
target_arch = "wasm32"
|
||||
)))]
|
||||
$item
|
||||
)*
|
||||
@@ -465,9 +469,28 @@ macro_rules! cfg_not_has_atomic_u64 {
|
||||
target_arch = "arm",
|
||||
target_arch = "mips",
|
||||
target_arch = "powerpc",
|
||||
target_arch = "riscv32"
|
||||
target_arch = "riscv32",
|
||||
target_arch = "wasm32"
|
||||
))]
|
||||
$item
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! cfg_not_wasi {
|
||||
($($item:item)*) => {
|
||||
$(
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
$item
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! cfg_is_wasm_not_wasi {
|
||||
($($item:item)*) => {
|
||||
$(
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
$item
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@
|
||||
//! [`UnixDatagram`]: UnixDatagram
|
||||
|
||||
mod addr;
|
||||
#[cfg(feature = "net")]
|
||||
pub(crate) use addr::to_socket_addrs;
|
||||
cfg_not_wasi! {
|
||||
#[cfg(feature = "net")]
|
||||
pub(crate) use addr::to_socket_addrs;
|
||||
}
|
||||
pub use addr::ToSocketAddrs;
|
||||
|
||||
cfg_net! {
|
||||
@@ -33,11 +35,13 @@ cfg_net! {
|
||||
|
||||
pub mod tcp;
|
||||
pub use tcp::listener::TcpListener;
|
||||
pub use tcp::socket::TcpSocket;
|
||||
pub use tcp::stream::TcpStream;
|
||||
cfg_not_wasi! {
|
||||
pub use tcp::socket::TcpSocket;
|
||||
|
||||
mod udp;
|
||||
pub use udp::UdpSocket;
|
||||
mod udp;
|
||||
pub use udp::UdpSocket;
|
||||
}
|
||||
}
|
||||
|
||||
cfg_net_unix! {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::io::{Interest, PollEvented};
|
||||
use crate::net::tcp::TcpStream;
|
||||
use crate::net::{to_socket_addrs, ToSocketAddrs};
|
||||
|
||||
cfg_not_wasi! {
|
||||
use crate::net::{to_socket_addrs, ToSocketAddrs};
|
||||
}
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
@@ -55,68 +58,70 @@ cfg_net! {
|
||||
}
|
||||
|
||||
impl TcpListener {
|
||||
/// Creates a new TcpListener, which will be bound to the specified address.
|
||||
///
|
||||
/// The returned listener is ready for accepting connections.
|
||||
///
|
||||
/// Binding with a port number of 0 will request that the OS assigns a port
|
||||
/// to this listener. The port allocated can be queried via the `local_addr`
|
||||
/// method.
|
||||
///
|
||||
/// The address type can be any implementor of the [`ToSocketAddrs`] trait.
|
||||
/// If `addr` yields multiple addresses, bind will be attempted with each of
|
||||
/// the addresses until one succeeds and returns the listener. If none of
|
||||
/// the addresses succeed in creating a listener, the error returned from
|
||||
/// the last attempt (the last address) is returned.
|
||||
///
|
||||
/// This function sets the `SO_REUSEADDR` option on the socket.
|
||||
///
|
||||
/// To configure the socket before binding, you can use the [`TcpSocket`]
|
||||
/// type.
|
||||
///
|
||||
/// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
|
||||
/// [`TcpSocket`]: struct@crate::net::TcpSocket
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpListener;
|
||||
///
|
||||
/// use std::io;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() -> io::Result<()> {
|
||||
/// let listener = TcpListener::bind("127.0.0.1:2345").await?;
|
||||
///
|
||||
/// // use the listener
|
||||
///
|
||||
/// # let _ = listener;
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<TcpListener> {
|
||||
let addrs = to_socket_addrs(addr).await?;
|
||||
cfg_not_wasi! {
|
||||
/// Creates a new TcpListener, which will be bound to the specified address.
|
||||
///
|
||||
/// The returned listener is ready for accepting connections.
|
||||
///
|
||||
/// Binding with a port number of 0 will request that the OS assigns a port
|
||||
/// to this listener. The port allocated can be queried via the `local_addr`
|
||||
/// method.
|
||||
///
|
||||
/// The address type can be any implementor of the [`ToSocketAddrs`] trait.
|
||||
/// If `addr` yields multiple addresses, bind will be attempted with each of
|
||||
/// the addresses until one succeeds and returns the listener. If none of
|
||||
/// the addresses succeed in creating a listener, the error returned from
|
||||
/// the last attempt (the last address) is returned.
|
||||
///
|
||||
/// This function sets the `SO_REUSEADDR` option on the socket.
|
||||
///
|
||||
/// To configure the socket before binding, you can use the [`TcpSocket`]
|
||||
/// type.
|
||||
///
|
||||
/// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
|
||||
/// [`TcpSocket`]: struct@crate::net::TcpSocket
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpListener;
|
||||
///
|
||||
/// use std::io;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() -> io::Result<()> {
|
||||
/// let listener = TcpListener::bind("127.0.0.1:2345").await?;
|
||||
///
|
||||
/// // use the listener
|
||||
///
|
||||
/// # let _ = listener;
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<TcpListener> {
|
||||
let addrs = to_socket_addrs(addr).await?;
|
||||
|
||||
let mut last_err = None;
|
||||
let mut last_err = None;
|
||||
|
||||
for addr in addrs {
|
||||
match TcpListener::bind_addr(addr) {
|
||||
Ok(listener) => return Ok(listener),
|
||||
Err(e) => last_err = Some(e),
|
||||
for addr in addrs {
|
||||
match TcpListener::bind_addr(addr) {
|
||||
Ok(listener) => return Ok(listener),
|
||||
Err(e) => last_err = Some(e),
|
||||
}
|
||||
}
|
||||
|
||||
Err(last_err.unwrap_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"could not resolve to any address",
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
Err(last_err.unwrap_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"could not resolve to any address",
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
fn bind_addr(addr: SocketAddr) -> io::Result<TcpListener> {
|
||||
let listener = mio::net::TcpListener::bind(addr)?;
|
||||
TcpListener::new(listener)
|
||||
fn bind_addr(addr: SocketAddr) -> io::Result<TcpListener> {
|
||||
let listener = mio::net::TcpListener::bind(addr)?;
|
||||
TcpListener::new(listener)
|
||||
}
|
||||
}
|
||||
|
||||
/// Accepts a new incoming connection from this listener.
|
||||
@@ -267,11 +272,22 @@ impl TcpListener {
|
||||
.map(|io| io.into_raw_socket())
|
||||
.map(|raw_socket| unsafe { std::net::TcpListener::from_raw_socket(raw_socket) })
|
||||
}
|
||||
|
||||
#[cfg(target_os = "wasi")]
|
||||
{
|
||||
use std::os::wasi::io::{FromRawFd, IntoRawFd};
|
||||
self.io
|
||||
.into_inner()
|
||||
.map(|io| io.into_raw_fd())
|
||||
.map(|raw_fd| unsafe { std::net::TcpListener::from_raw_fd(raw_fd) })
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new(listener: mio::net::TcpListener) -> io::Result<TcpListener> {
|
||||
let io = PollEvented::new(listener)?;
|
||||
Ok(TcpListener { io })
|
||||
cfg_not_wasi! {
|
||||
pub(crate) fn new(listener: mio::net::TcpListener) -> io::Result<TcpListener> {
|
||||
let io = PollEvented::new(listener)?;
|
||||
Ok(TcpListener { io })
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the local address that this listener is bound to.
|
||||
@@ -384,6 +400,20 @@ mod sys {
|
||||
}
|
||||
}
|
||||
|
||||
cfg_unstable! {
|
||||
#[cfg(target_os = "wasi")]
|
||||
mod sys {
|
||||
use super::TcpListener;
|
||||
use std::os::wasi::prelude::*;
|
||||
|
||||
impl AsRawFd for TcpListener {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
self.io.as_raw_fd()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
mod sys {
|
||||
use super::TcpListener;
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
pub(crate) mod listener;
|
||||
|
||||
pub(crate) mod socket;
|
||||
cfg_not_wasi! {
|
||||
pub(crate) mod socket;
|
||||
}
|
||||
|
||||
mod split;
|
||||
pub use split::{ReadHalf, WriteHalf};
|
||||
|
||||
+149
-121
@@ -1,8 +1,12 @@
|
||||
use crate::future::poll_fn;
|
||||
cfg_not_wasi! {
|
||||
use crate::future::poll_fn;
|
||||
use crate::net::{to_socket_addrs, ToSocketAddrs};
|
||||
use std::time::Duration;
|
||||
}
|
||||
|
||||
use crate::io::{AsyncRead, AsyncWrite, Interest, PollEvented, ReadBuf, Ready};
|
||||
use crate::net::tcp::split::{split, ReadHalf, WriteHalf};
|
||||
use crate::net::tcp::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf};
|
||||
use crate::net::{to_socket_addrs, ToSocketAddrs};
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
@@ -10,7 +14,6 @@ use std::io;
|
||||
use std::net::{Shutdown, SocketAddr};
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use std::time::Duration;
|
||||
|
||||
cfg_io_util! {
|
||||
use bytes::BufMut;
|
||||
@@ -70,86 +73,88 @@ cfg_net! {
|
||||
}
|
||||
|
||||
impl TcpStream {
|
||||
/// Opens a TCP connection to a remote host.
|
||||
///
|
||||
/// `addr` is an address of the remote host. Anything which implements the
|
||||
/// [`ToSocketAddrs`] trait can be supplied as the address. If `addr`
|
||||
/// yields multiple addresses, connect will be attempted with each of the
|
||||
/// addresses until a connection is successful. If none of the addresses
|
||||
/// result in a successful connection, the error returned from the last
|
||||
/// connection attempt (the last address) is returned.
|
||||
///
|
||||
/// To configure the socket before connecting, you can use the [`TcpSocket`]
|
||||
/// type.
|
||||
///
|
||||
/// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
|
||||
/// [`TcpSocket`]: struct@crate::net::TcpSocket
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpStream;
|
||||
/// use tokio::io::AsyncWriteExt;
|
||||
/// use std::error::Error;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() -> Result<(), Box<dyn Error>> {
|
||||
/// // Connect to a peer
|
||||
/// let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||
///
|
||||
/// // Write some data.
|
||||
/// stream.write_all(b"hello world!").await?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// The [`write_all`] method is defined on the [`AsyncWriteExt`] trait.
|
||||
///
|
||||
/// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all
|
||||
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
|
||||
pub async fn connect<A: ToSocketAddrs>(addr: A) -> io::Result<TcpStream> {
|
||||
let addrs = to_socket_addrs(addr).await?;
|
||||
cfg_not_wasi! {
|
||||
/// Opens a TCP connection to a remote host.
|
||||
///
|
||||
/// `addr` is an address of the remote host. Anything which implements the
|
||||
/// [`ToSocketAddrs`] trait can be supplied as the address. If `addr`
|
||||
/// yields multiple addresses, connect will be attempted with each of the
|
||||
/// addresses until a connection is successful. If none of the addresses
|
||||
/// result in a successful connection, the error returned from the last
|
||||
/// connection attempt (the last address) is returned.
|
||||
///
|
||||
/// To configure the socket before connecting, you can use the [`TcpSocket`]
|
||||
/// type.
|
||||
///
|
||||
/// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
|
||||
/// [`TcpSocket`]: struct@crate::net::TcpSocket
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpStream;
|
||||
/// use tokio::io::AsyncWriteExt;
|
||||
/// use std::error::Error;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() -> Result<(), Box<dyn Error>> {
|
||||
/// // Connect to a peer
|
||||
/// let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||
///
|
||||
/// // Write some data.
|
||||
/// stream.write_all(b"hello world!").await?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// The [`write_all`] method is defined on the [`AsyncWriteExt`] trait.
|
||||
///
|
||||
/// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all
|
||||
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
|
||||
pub async fn connect<A: ToSocketAddrs>(addr: A) -> io::Result<TcpStream> {
|
||||
let addrs = to_socket_addrs(addr).await?;
|
||||
|
||||
let mut last_err = None;
|
||||
let mut last_err = None;
|
||||
|
||||
for addr in addrs {
|
||||
match TcpStream::connect_addr(addr).await {
|
||||
Ok(stream) => return Ok(stream),
|
||||
Err(e) => last_err = Some(e),
|
||||
for addr in addrs {
|
||||
match TcpStream::connect_addr(addr).await {
|
||||
Ok(stream) => return Ok(stream),
|
||||
Err(e) => last_err = Some(e),
|
||||
}
|
||||
}
|
||||
|
||||
Err(last_err.unwrap_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"could not resolve to any address",
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
Err(last_err.unwrap_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"could not resolve to any address",
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
||||
/// Establishes a connection to the specified `addr`.
|
||||
async fn connect_addr(addr: SocketAddr) -> io::Result<TcpStream> {
|
||||
let sys = mio::net::TcpStream::connect(addr)?;
|
||||
TcpStream::connect_mio(sys).await
|
||||
}
|
||||
|
||||
pub(crate) async fn connect_mio(sys: mio::net::TcpStream) -> io::Result<TcpStream> {
|
||||
let stream = TcpStream::new(sys)?;
|
||||
|
||||
// Once we've connected, wait for the stream to be writable as
|
||||
// that's when the actual connection has been initiated. Once we're
|
||||
// writable we check for `take_socket_error` to see if the connect
|
||||
// actually hit an error or not.
|
||||
//
|
||||
// If all that succeeded then we ship everything on up.
|
||||
poll_fn(|cx| stream.io.registration().poll_write_ready(cx)).await?;
|
||||
|
||||
if let Some(e) = stream.io.take_error()? {
|
||||
return Err(e);
|
||||
/// Establishes a connection to the specified `addr`.
|
||||
async fn connect_addr(addr: SocketAddr) -> io::Result<TcpStream> {
|
||||
let sys = mio::net::TcpStream::connect(addr)?;
|
||||
TcpStream::connect_mio(sys).await
|
||||
}
|
||||
|
||||
Ok(stream)
|
||||
pub(crate) async fn connect_mio(sys: mio::net::TcpStream) -> io::Result<TcpStream> {
|
||||
let stream = TcpStream::new(sys)?;
|
||||
|
||||
// Once we've connected, wait for the stream to be writable as
|
||||
// that's when the actual connection has been initiated. Once we're
|
||||
// writable we check for `take_socket_error` to see if the connect
|
||||
// actually hit an error or not.
|
||||
//
|
||||
// If all that succeeded then we ship everything on up.
|
||||
poll_fn(|cx| stream.io.registration().poll_write_ready(cx)).await?;
|
||||
|
||||
if let Some(e) = stream.io.take_error()? {
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
Ok(stream)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new(connected: mio::net::TcpStream) -> io::Result<TcpStream> {
|
||||
@@ -244,6 +249,15 @@ impl TcpStream {
|
||||
.map(|io| io.into_raw_socket())
|
||||
.map(|raw_socket| unsafe { std::net::TcpStream::from_raw_socket(raw_socket) })
|
||||
}
|
||||
|
||||
#[cfg(target_os = "wasi")]
|
||||
{
|
||||
use std::os::wasi::io::{FromRawFd, IntoRawFd};
|
||||
self.io
|
||||
.into_inner()
|
||||
.map(|io| io.into_raw_fd())
|
||||
.map(|raw_fd| unsafe { std::net::TcpStream::from_raw_fd(raw_fd) })
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the local address that this stream is bound to.
|
||||
@@ -1077,52 +1091,54 @@ impl TcpStream {
|
||||
self.io.set_nodelay(nodelay)
|
||||
}
|
||||
|
||||
/// Reads the linger duration for this socket by getting the `SO_LINGER`
|
||||
/// option.
|
||||
///
|
||||
/// For more information about this option, see [`set_linger`].
|
||||
///
|
||||
/// [`set_linger`]: TcpStream::set_linger
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpStream;
|
||||
///
|
||||
/// # async fn dox() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||
///
|
||||
/// println!("{:?}", stream.linger()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn linger(&self) -> io::Result<Option<Duration>> {
|
||||
socket2::SockRef::from(self).linger()
|
||||
}
|
||||
cfg_not_wasi! {
|
||||
/// Reads the linger duration for this socket by getting the `SO_LINGER`
|
||||
/// option.
|
||||
///
|
||||
/// For more information about this option, see [`set_linger`].
|
||||
///
|
||||
/// [`set_linger`]: TcpStream::set_linger
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpStream;
|
||||
///
|
||||
/// # async fn dox() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||
///
|
||||
/// println!("{:?}", stream.linger()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn linger(&self) -> io::Result<Option<Duration>> {
|
||||
socket2::SockRef::from(self).linger()
|
||||
}
|
||||
|
||||
/// Sets the linger duration of this socket by setting the SO_LINGER option.
|
||||
///
|
||||
/// This option controls the action taken when a stream has unsent messages and the stream is
|
||||
/// closed. If SO_LINGER is set, the system shall block the process until it can transmit the
|
||||
/// data or until the time expires.
|
||||
///
|
||||
/// If SO_LINGER is not specified, and the stream is closed, the system handles the call in a
|
||||
/// way that allows the process to continue as quickly as possible.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpStream;
|
||||
///
|
||||
/// # async fn dox() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||
///
|
||||
/// stream.set_linger(None)?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn set_linger(&self, dur: Option<Duration>) -> io::Result<()> {
|
||||
socket2::SockRef::from(self).set_linger(dur)
|
||||
/// Sets the linger duration of this socket by setting the SO_LINGER option.
|
||||
///
|
||||
/// This option controls the action taken when a stream has unsent messages and the stream is
|
||||
/// closed. If SO_LINGER is set, the system shall block the process until it can transmit the
|
||||
/// data or until the time expires.
|
||||
///
|
||||
/// If SO_LINGER is not specified, and the stream is closed, the system handles the call in a
|
||||
/// way that allows the process to continue as quickly as possible.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use tokio::net::TcpStream;
|
||||
///
|
||||
/// # async fn dox() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||
///
|
||||
/// stream.set_linger(None)?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn set_linger(&self, dur: Option<Duration>) -> io::Result<()> {
|
||||
socket2::SockRef::from(self).set_linger(dur)
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the value of the `IP_TTL` option for this socket.
|
||||
@@ -1315,3 +1331,15 @@ mod sys {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(tokio_unstable, target_os = "wasi"))]
|
||||
mod sys {
|
||||
use super::TcpStream;
|
||||
use std::os::wasi::prelude::*;
|
||||
|
||||
impl AsRawFd for TcpStream {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
self.io.as_raw_fd()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,11 @@ impl Park for ParkThread {
|
||||
}
|
||||
|
||||
fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> {
|
||||
// Wasi doesn't have threads, so just sleep.
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
self.inner.park_timeout(duration);
|
||||
#[cfg(target_os = "wasi")]
|
||||
std::thread::sleep(duration);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -174,7 +174,7 @@ pub(crate) type ThreadNameFn = std::sync::Arc<dyn Fn() -> String + Send + Sync +
|
||||
|
||||
pub(crate) enum Kind {
|
||||
CurrentThread,
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
MultiThread,
|
||||
}
|
||||
|
||||
@@ -197,14 +197,16 @@ impl Builder {
|
||||
Builder::new(Kind::CurrentThread, 31, EVENT_INTERVAL)
|
||||
}
|
||||
|
||||
/// Returns a new builder with the multi thread scheduler selected.
|
||||
///
|
||||
/// Configuration methods can be chained on the return value.
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
|
||||
pub fn new_multi_thread() -> Builder {
|
||||
// The number `61` is fairly arbitrary. I believe this value was copied from golang.
|
||||
Builder::new(Kind::MultiThread, 61, 61)
|
||||
cfg_not_wasi! {
|
||||
/// Returns a new builder with the multi thread scheduler selected.
|
||||
///
|
||||
/// Configuration methods can be chained on the return value.
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
|
||||
pub fn new_multi_thread() -> Builder {
|
||||
// The number `61` is fairly arbitrary. I believe this value was copied from golang.
|
||||
Builder::new(Kind::MultiThread, 61, 61)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a new runtime builder initialized with default configuration
|
||||
@@ -617,7 +619,7 @@ impl Builder {
|
||||
pub fn build(&mut self) -> io::Result<Runtime> {
|
||||
match &self.kind {
|
||||
Kind::CurrentThread => self.build_basic_runtime(),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Kind::MultiThread => self.build_threaded_runtime(),
|
||||
}
|
||||
}
|
||||
@@ -626,7 +628,7 @@ impl Builder {
|
||||
driver::Cfg {
|
||||
enable_pause_time: match self.kind {
|
||||
Kind::CurrentThread => true,
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Kind::MultiThread => false,
|
||||
},
|
||||
enable_io: self.enable_io,
|
||||
|
||||
+39
-36
@@ -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! {
|
||||
@@ -303,7 +304,7 @@ cfg_rt! {
|
||||
CurrentThread(BasicScheduler),
|
||||
|
||||
/// Execute tasks across multiple threads.
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
ThreadPool(ThreadPool),
|
||||
}
|
||||
|
||||
@@ -311,39 +312,41 @@ cfg_rt! {
|
||||
type Callback = std::sync::Arc<dyn Fn() + Send + Sync>;
|
||||
|
||||
impl Runtime {
|
||||
/// Creates a new runtime instance with default configuration values.
|
||||
///
|
||||
/// This results in the multi threaded scheduler, I/O driver, and time driver being
|
||||
/// initialized.
|
||||
///
|
||||
/// Most applications will not need to call this function directly. Instead,
|
||||
/// they will use the [`#[tokio::main]` attribute][main]. When a more complex
|
||||
/// configuration is necessary, the [runtime builder] may be used.
|
||||
///
|
||||
/// See [module level][mod] documentation for more details.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Creating a new `Runtime` with default configuration values.
|
||||
///
|
||||
/// ```
|
||||
/// use tokio::runtime::Runtime;
|
||||
///
|
||||
/// let rt = Runtime::new()
|
||||
/// .unwrap();
|
||||
///
|
||||
/// // Use the runtime...
|
||||
/// ```
|
||||
///
|
||||
/// [mod]: index.html
|
||||
/// [main]: ../attr.main.html
|
||||
/// [threaded scheduler]: index.html#threaded-scheduler
|
||||
/// [basic scheduler]: index.html#basic-scheduler
|
||||
/// [runtime builder]: crate::runtime::Builder
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
|
||||
pub fn new() -> std::io::Result<Runtime> {
|
||||
Builder::new_multi_thread().enable_all().build()
|
||||
cfg_not_wasi! {
|
||||
/// Creates a new runtime instance with default configuration values.
|
||||
///
|
||||
/// This results in the multi threaded scheduler, I/O driver, and time driver being
|
||||
/// initialized.
|
||||
///
|
||||
/// Most applications will not need to call this function directly. Instead,
|
||||
/// they will use the [`#[tokio::main]` attribute][main]. When a more complex
|
||||
/// configuration is necessary, the [runtime builder] may be used.
|
||||
///
|
||||
/// See [module level][mod] documentation for more details.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Creating a new `Runtime` with default configuration values.
|
||||
///
|
||||
/// ```
|
||||
/// use tokio::runtime::Runtime;
|
||||
///
|
||||
/// let rt = Runtime::new()
|
||||
/// .unwrap();
|
||||
///
|
||||
/// // Use the runtime...
|
||||
/// ```
|
||||
///
|
||||
/// [mod]: index.html
|
||||
/// [main]: ../attr.main.html
|
||||
/// [threaded scheduler]: index.html#threaded-scheduler
|
||||
/// [basic scheduler]: index.html#basic-scheduler
|
||||
/// [runtime builder]: crate::runtime::Builder
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
|
||||
pub fn new() -> std::io::Result<Runtime> {
|
||||
Builder::new_multi_thread().enable_all().build()
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a handle to the runtime's spawner.
|
||||
@@ -480,7 +483,7 @@ cfg_rt! {
|
||||
|
||||
match &self.kind {
|
||||
Kind::CurrentThread(exec) => exec.block_on(future),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Kind::ThreadPool(exec) => exec.block_on(future),
|
||||
}
|
||||
}
|
||||
@@ -610,7 +613,7 @@ cfg_rt! {
|
||||
},
|
||||
}
|
||||
},
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Kind::ThreadPool(_) => {
|
||||
// The threaded scheduler drops its tasks on its worker threads, which is
|
||||
// already in the runtime's context.
|
||||
|
||||
@@ -10,13 +10,13 @@ cfg_rt_multi_thread! {
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) enum Spawner {
|
||||
Basic(basic_scheduler::Spawner),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
ThreadPool(thread_pool::Spawner),
|
||||
}
|
||||
|
||||
impl Spawner {
|
||||
pub(crate) fn shutdown(&mut self) {
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
{
|
||||
if let Spawner::ThreadPool(spawner) = self {
|
||||
spawner.shutdown();
|
||||
@@ -31,7 +31,7 @@ impl Spawner {
|
||||
{
|
||||
match self {
|
||||
Spawner::Basic(spawner) => spawner.spawn(future, id),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Spawner::ThreadPool(spawner) => spawner.spawn(future, id),
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ impl Spawner {
|
||||
pub(crate) fn as_handle_inner(&self) -> &HandleInner {
|
||||
match self {
|
||||
Spawner::Basic(spawner) => spawner.as_handle_inner(),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Spawner::ThreadPool(spawner) => spawner.as_handle_inner(),
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ cfg_metrics! {
|
||||
pub(crate) fn num_workers(&self) -> usize {
|
||||
match self {
|
||||
Spawner::Basic(_) => 1,
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Spawner::ThreadPool(spawner) => spawner.num_workers(),
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ cfg_metrics! {
|
||||
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {
|
||||
match self {
|
||||
Spawner::Basic(spawner) => spawner.scheduler_metrics(),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Spawner::ThreadPool(spawner) => spawner.scheduler_metrics(),
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ cfg_metrics! {
|
||||
pub(crate) fn worker_metrics(&self, worker: usize) -> &WorkerMetrics {
|
||||
match self {
|
||||
Spawner::Basic(spawner) => spawner.worker_metrics(worker),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Spawner::ThreadPool(spawner) => spawner.worker_metrics(worker),
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ cfg_metrics! {
|
||||
pub(crate) fn injection_queue_depth(&self) -> usize {
|
||||
match self {
|
||||
Spawner::Basic(spawner) => spawner.injection_queue_depth(),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Spawner::ThreadPool(spawner) => spawner.injection_queue_depth(),
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ cfg_metrics! {
|
||||
pub(crate) fn worker_local_queue_depth(&self, worker: usize) -> usize {
|
||||
match self {
|
||||
Spawner::Basic(spawner) => spawner.worker_metrics(worker).queue_depth(),
|
||||
#[cfg(feature = "rt-multi-thread")]
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
|
||||
Spawner::ThreadPool(spawner) => spawner.worker_local_queue_depth(worker),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ impl AssertSync for AtomicWaker {}
|
||||
impl AssertSend for Waker {}
|
||||
impl AssertSync for Waker {}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::mem::ManuallyDrop;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, RawWaker, RawWakerVTable, Waker};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::sync::batch_semaphore::Semaphore;
|
||||
use tokio_test::*;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -278,8 +278,10 @@
|
||||
cfg_rt! {
|
||||
pub use crate::runtime::task::{JoinError, JoinHandle};
|
||||
|
||||
mod blocking;
|
||||
pub use blocking::spawn_blocking;
|
||||
cfg_not_wasi! {
|
||||
mod blocking;
|
||||
pub use blocking::spawn_blocking;
|
||||
}
|
||||
|
||||
mod spawn;
|
||||
pub use spawn::spawn;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![cfg(not(target_os = "wasi"))]
|
||||
|
||||
use std::{task::Context, time::Duration};
|
||||
|
||||
#[cfg(not(loom))]
|
||||
|
||||
@@ -631,6 +631,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn run_fuzz(ops: Vec<usize>) {
|
||||
use std::collections::VecDeque;
|
||||
|
||||
|
||||
@@ -127,70 +127,96 @@ macro_rules! assert_value {
|
||||
};
|
||||
}
|
||||
|
||||
assert_value!(tokio::fs::DirBuilder: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::DirEntry: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::File: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::OpenOptions: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::ReadDir: Send & Sync & Unpin);
|
||||
macro_rules! cfg_not_wasi {
|
||||
($($item:item)*) => {
|
||||
$(
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
$item
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
async_assert_fn!(tokio::fs::canonicalize(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::copy(&str, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::create_dir(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::create_dir_all(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::hard_link(&str, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::metadata(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read_dir(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read_link(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read_to_string(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::remove_dir(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::remove_dir_all(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::remove_file(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::rename(&str, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::set_permissions(&str, std::fs::Permissions): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::symlink_metadata(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::write(&str, Vec<u8>): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::ReadDir::next_entry(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::OpenOptions::open(_, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::DirBuilder::create(_, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::DirEntry::metadata(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::DirEntry::file_type(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::open(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::create(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::sync_all(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::sync_data(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::set_len(_, u64): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::metadata(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::try_clone(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::into_std(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::set_permissions(_, std::fs::Permissions): Send & Sync & !Unpin);
|
||||
cfg_not_wasi! {
|
||||
mod fs {
|
||||
use super::*;
|
||||
assert_value!(tokio::fs::DirBuilder: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::DirEntry: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::File: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::OpenOptions: Send & Sync & Unpin);
|
||||
assert_value!(tokio::fs::ReadDir: Send & Sync & Unpin);
|
||||
|
||||
async_assert_fn!(tokio::fs::canonicalize(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::copy(&str, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::create_dir(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::create_dir_all(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::hard_link(&str, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::metadata(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read_dir(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read_link(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::read_to_string(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::remove_dir(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::remove_dir_all(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::remove_file(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::rename(&str, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::set_permissions(&str, std::fs::Permissions): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::symlink_metadata(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::write(&str, Vec<u8>): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::ReadDir::next_entry(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::OpenOptions::open(_, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::DirBuilder::create(_, &str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::DirEntry::metadata(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::DirEntry::file_type(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::open(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::create(&str): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::sync_all(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::sync_data(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::set_len(_, u64): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::metadata(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::try_clone(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::fs::File::into_std(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(
|
||||
tokio::fs::File::set_permissions(_, std::fs::Permissions): Send & Sync & !Unpin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
cfg_not_wasi! {
|
||||
assert_value!(tokio::net::TcpSocket: Send & Sync & Unpin);
|
||||
async_assert_fn!(tokio::net::TcpListener::bind(SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::TcpStream::connect(SocketAddr): Send & Sync & !Unpin);
|
||||
}
|
||||
|
||||
assert_value!(tokio::net::TcpListener: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::TcpSocket: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::TcpStream: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::UdpSocket: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::tcp::OwnedReadHalf: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::tcp::OwnedWriteHalf: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::tcp::ReadHalf<'_>: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::tcp::ReuniteError: Send & Sync & Unpin);
|
||||
assert_value!(tokio::net::tcp::WriteHalf<'_>: Send & Sync & Unpin);
|
||||
async_assert_fn!(tokio::net::TcpListener::accept(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::TcpListener::bind(SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::TcpStream::connect(SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::TcpStream::peek(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::TcpStream::readable(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::TcpStream::ready(_, tokio::io::Interest): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::TcpStream::writable(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::bind(SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::connect(_, SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::peek_from(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::readable(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::ready(_, tokio::io::Interest): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::recv(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::recv_from(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::send(_, &[u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::send_to(_, &[u8], SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::writable(_): Send & Sync & !Unpin);
|
||||
|
||||
// Wasi does not support UDP
|
||||
cfg_not_wasi! {
|
||||
mod udp_socket {
|
||||
use super::*;
|
||||
assert_value!(tokio::net::UdpSocket: Send & Sync & Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::bind(SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::connect(_, SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::peek_from(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::readable(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::ready(_, tokio::io::Interest): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::recv(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::recv_from(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::send(_, &[u8]): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::send_to(_, &[u8], SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::UdpSocket::writable(_): Send & Sync & !Unpin);
|
||||
}
|
||||
}
|
||||
async_assert_fn!(tokio::net::lookup_host(SocketAddr): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::net::tcp::ReadHalf::peek(_, &mut [u8]): Send & Sync & !Unpin);
|
||||
|
||||
@@ -242,16 +268,22 @@ mod windows_named_pipe {
|
||||
async_assert_fn!(NamedPipeServer::writable(_): Send & Sync & !Unpin);
|
||||
}
|
||||
|
||||
assert_value!(tokio::process::Child: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::ChildStderr: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::ChildStdin: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::ChildStdout: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::Command: Send & Sync & Unpin);
|
||||
async_assert_fn!(tokio::process::Child::kill(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::process::Child::wait(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::process::Child::wait_with_output(_): Send & Sync & !Unpin);
|
||||
cfg_not_wasi! {
|
||||
mod test_process {
|
||||
use super::*;
|
||||
assert_value!(tokio::process::Child: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::ChildStderr: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::ChildStdin: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::ChildStdout: Send & Sync & Unpin);
|
||||
assert_value!(tokio::process::Command: Send & Sync & Unpin);
|
||||
async_assert_fn!(tokio::process::Child::kill(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::process::Child::wait(_): Send & Sync & !Unpin);
|
||||
async_assert_fn!(tokio::process::Child::wait_with_output(_): Send & Sync & !Unpin);
|
||||
}
|
||||
|
||||
async_assert_fn!(tokio::signal::ctrl_c(): Send & Sync & !Unpin);
|
||||
}
|
||||
|
||||
async_assert_fn!(tokio::signal::ctrl_c(): Send & Sync & !Unpin);
|
||||
#[cfg(unix)]
|
||||
mod unix_signal {
|
||||
use super::*;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind()
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
|
||||
|
||||
use tokio::fs;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
|
||||
|
||||
use tempfile::tempdir;
|
||||
use tokio::fs;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support directory operations
|
||||
|
||||
use tokio::fs;
|
||||
use tokio_test::{assert_err, assert_ok};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
|
||||
|
||||
use std::io::prelude::*;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
|
||||
|
||||
use tokio::fs;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind()
|
||||
|
||||
use std::time::Duration;
|
||||
use tokio::io::{self, copy_bidirectional, AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
// Wasi does not support panic recovery or threading
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))]
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::runtime;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::runtime;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
|
||||
|
||||
use tempfile::NamedTempFile;
|
||||
use tokio::fs::File;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
||||
|
||||
use std::task::{Context, Poll};
|
||||
use std::{error::Error, pin::Pin};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
||||
|
||||
use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf};
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
||||
|
||||
use tokio::io::{split, AsyncRead, AsyncWrite, ReadBuf, ReadHalf, WriteHalf};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
||||
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
||||
|
||||
struct PanicsOnDrop;
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
#![allow(clippy::blacklisted_name)]
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
use tokio::sync::{oneshot, Semaphore};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#![cfg(feature = "macros")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
async fn one() {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use std as tokio;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#![cfg(feature = "macros")]
|
||||
#![allow(clippy::blacklisted_name)]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading
|
||||
|
||||
use tokio::test;
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ use std::sync::Arc;
|
||||
use tokio::sync::{oneshot, Semaphore};
|
||||
use tokio_test::{assert_pending, assert_ready, task};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
#[maybe_tokio_test]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery or bind
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support direct socket operations
|
||||
|
||||
use tokio::net;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
||||
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi cannot run system commands
|
||||
|
||||
use tokio::process::Command;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
@@ -178,6 +178,7 @@ fn drop_tasks_in_context() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
|
||||
#[should_panic(expected = "boom")]
|
||||
fn wake_in_drop_after_panic() {
|
||||
let (tx, rx) = oneshot::channel::<()>();
|
||||
@@ -238,6 +239,7 @@ fn spawn_two() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "wasi", ignore = "WASI: std::thread::spawn not supported")]
|
||||
#[test]
|
||||
fn spawn_remote() {
|
||||
let rt = rt();
|
||||
@@ -274,6 +276,7 @@ fn spawn_remote() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
|
||||
#[should_panic(
|
||||
expected = "A Tokio 1.x context was found, but timers are disabled. Call `enable_time` on the runtime builder to enable timers."
|
||||
)]
|
||||
@@ -312,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;
|
||||
|
||||
@@ -340,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};
|
||||
|
||||
@@ -18,6 +18,7 @@ macro_rules! rt_test {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
mod threaded_scheduler_4_threads {
|
||||
$($t)*
|
||||
|
||||
@@ -31,6 +32,7 @@ macro_rules! rt_test {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
mod threaded_scheduler_1_thread {
|
||||
$($t)*
|
||||
|
||||
@@ -55,18 +57,30 @@ fn send_sync_bound() {
|
||||
}
|
||||
|
||||
rt_test! {
|
||||
use tokio::net::{TcpListener, TcpStream, UdpSocket};
|
||||
#[cfg(not(target_os="wasi"))]
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
#[cfg(not(target_os="wasi"))]
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::{task, time};
|
||||
use tokio_test::{assert_err, assert_ok};
|
||||
|
||||
#[cfg(not(target_os="wasi"))]
|
||||
use tokio_test::assert_err;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
use futures::future::poll_fn;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::{mpsc, Arc};
|
||||
|
||||
#[cfg(not(target_os="wasi"))]
|
||||
use std::sync::mpsc;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
#[cfg(not(target_os="wasi"))]
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -83,6 +97,7 @@ rt_test! {
|
||||
}
|
||||
|
||||
|
||||
#[cfg(not(target_os="wasi"))]
|
||||
#[test]
|
||||
fn block_on_async() {
|
||||
let rt = rt();
|
||||
@@ -164,6 +179,7 @@ rt_test! {
|
||||
assert_eq!(out, "ZOMG");
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn spawn_many_from_block_on() {
|
||||
use tokio::sync::mpsc;
|
||||
@@ -214,6 +230,7 @@ rt_test! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn spawn_many_from_task() {
|
||||
use tokio::sync::mpsc;
|
||||
@@ -329,6 +346,7 @@ rt_test! {
|
||||
assert_eq!(out, "ZOMG");
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn complete_block_on_under_load() {
|
||||
let rt = rt();
|
||||
@@ -352,6 +370,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn complete_task_under_load() {
|
||||
let rt = rt();
|
||||
@@ -381,6 +400,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn spawn_from_other_thread_idle() {
|
||||
let rt = rt();
|
||||
@@ -401,6 +421,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn spawn_from_other_thread_under_load() {
|
||||
let rt = rt();
|
||||
@@ -461,6 +482,7 @@ rt_test! {
|
||||
assert!(now.elapsed() >= dur);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support bind
|
||||
#[test]
|
||||
fn block_on_socket() {
|
||||
let rt = rt();
|
||||
@@ -481,6 +503,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn spawn_from_blocking() {
|
||||
let rt = rt();
|
||||
@@ -496,6 +519,7 @@ rt_test! {
|
||||
assert_eq!(out, "hello")
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn spawn_blocking_from_blocking() {
|
||||
let rt = rt();
|
||||
@@ -511,6 +535,7 @@ rt_test! {
|
||||
assert_eq!(out, "hello")
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn sleep_from_blocking() {
|
||||
let rt = rt();
|
||||
@@ -531,6 +556,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support bind
|
||||
#[test]
|
||||
fn socket_from_blocking() {
|
||||
let rt = rt();
|
||||
@@ -554,6 +580,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn always_active_parker() {
|
||||
// This test it to show that we will always have
|
||||
@@ -600,6 +627,7 @@ rt_test! {
|
||||
// concern. There also isn't a great/obvious solution to take. For now, the
|
||||
// test is disabled.
|
||||
#[cfg(not(windows))]
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support bind or threads
|
||||
fn io_driver_called_when_under_load() {
|
||||
let rt = rt();
|
||||
|
||||
@@ -635,6 +663,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn client_server_block_on() {
|
||||
let rt = rt();
|
||||
@@ -646,6 +675,7 @@ rt_test! {
|
||||
assert_err!(rx.try_recv());
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads or panic recovery")]
|
||||
#[test]
|
||||
fn panic_in_task() {
|
||||
let rt = rt();
|
||||
@@ -674,11 +704,13 @@ rt_test! {
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
|
||||
fn panic_in_block_on() {
|
||||
let rt = rt();
|
||||
rt.block_on(async { panic!() });
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
async fn yield_once() {
|
||||
let mut yielded = false;
|
||||
poll_fn(|cx| {
|
||||
@@ -816,8 +848,10 @@ rt_test! {
|
||||
assert!(drop_triggered.load(Ordering::Relaxed));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi doesn't support UDP or bind()
|
||||
#[test]
|
||||
fn io_notify_while_shutting_down() {
|
||||
use tokio::net::UdpSocket;
|
||||
use std::net::Ipv6Addr;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -851,6 +885,7 @@ rt_test! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn shutdown_timeout() {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
@@ -868,6 +903,7 @@ rt_test! {
|
||||
Arc::try_unwrap(runtime).unwrap().shutdown_timeout(Duration::from_millis(100));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
|
||||
#[test]
|
||||
fn shutdown_timeout_0() {
|
||||
let runtime = rt();
|
||||
@@ -899,6 +935,7 @@ rt_test! {
|
||||
// See https://github.com/rust-lang/rust/issues/74875
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads")]
|
||||
fn runtime_in_thread_local() {
|
||||
use std::cell::RefCell;
|
||||
use std::thread;
|
||||
@@ -918,6 +955,7 @@ rt_test! {
|
||||
}).join().unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="wasi"))] // Wasi does not support bind
|
||||
async fn client_server(tx: mpsc::Sender<()>) {
|
||||
let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
|
||||
|
||||
@@ -942,6 +980,7 @@ rt_test! {
|
||||
tx.send(()).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi does not support bind
|
||||
#[test]
|
||||
fn local_set_block_on_socket() {
|
||||
let rt = rt();
|
||||
@@ -963,6 +1002,7 @@ rt_test! {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi does not support bind
|
||||
#[test]
|
||||
fn local_set_client_server_block_on() {
|
||||
let rt = rt();
|
||||
@@ -976,6 +1016,7 @@ rt_test! {
|
||||
assert_err!(rx.try_recv());
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi does not support bind
|
||||
async fn client_server_local(tx: mpsc::Sender<()>) {
|
||||
let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
|
||||
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
use std::time::Duration;
|
||||
use tokio::runtime::{Handle, Runtime};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::task::spawn_blocking;
|
||||
use tokio::{fs, net, time};
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
use tokio::{net, time};
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
macro_rules! multi_threaded_rt_test {
|
||||
($($t:tt)*) => {
|
||||
mod threaded_scheduler_4_threads_only {
|
||||
@@ -45,6 +46,7 @@ macro_rules! multi_threaded_rt_test {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
macro_rules! rt_test {
|
||||
($($t:tt)*) => {
|
||||
mod current_thread_scheduler {
|
||||
@@ -124,7 +126,9 @@ fn unbounded_mpsc_channel() {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support file operations or bind
|
||||
rt_test! {
|
||||
use tokio::fs;
|
||||
// ==== spawn blocking futures ======
|
||||
|
||||
#[test]
|
||||
@@ -156,6 +160,7 @@ rt_test! {
|
||||
|
||||
#[test]
|
||||
fn basic_spawn_blocking() {
|
||||
use tokio::task::spawn_blocking;
|
||||
let rt = rt();
|
||||
let _enter = rt.enter();
|
||||
|
||||
@@ -171,6 +176,7 @@ rt_test! {
|
||||
|
||||
#[test]
|
||||
fn spawn_blocking_after_shutdown_fails() {
|
||||
use tokio::task::spawn_blocking;
|
||||
let rt = rt();
|
||||
let _enter = rt.enter();
|
||||
rt.shutdown_timeout(Duration::from_secs(1000));
|
||||
@@ -187,6 +193,7 @@ rt_test! {
|
||||
|
||||
#[test]
|
||||
fn spawn_blocking_started_before_shutdown_continues() {
|
||||
use tokio::task::spawn_blocking;
|
||||
let rt = rt();
|
||||
let _enter = rt.enter();
|
||||
|
||||
@@ -412,6 +419,7 @@ rt_test! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
multi_threaded_rt_test! {
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
@@ -474,6 +482,7 @@ multi_threaded_rt_test! {
|
||||
// ==== utils ======
|
||||
|
||||
/// Create a new multi threaded runtime
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
fn new_multi_thread(n: usize) -> Runtime {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(n)
|
||||
@@ -507,6 +516,7 @@ where
|
||||
f();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
{
|
||||
println!("multi thread (1 thread) runtime");
|
||||
|
||||
@@ -519,6 +529,7 @@ where
|
||||
f();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
{
|
||||
println!("multi thread (4 threads) runtime");
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
|
||||
|
||||
use futures::future;
|
||||
use std::error::Error;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))]
|
||||
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::runtime::{self, Runtime};
|
||||
use tokio::runtime;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio_test::{assert_err, assert_ok};
|
||||
|
||||
@@ -539,6 +539,6 @@ async fn test_block_in_place4() {
|
||||
tokio::task::block_in_place(|| {});
|
||||
}
|
||||
|
||||
fn rt() -> Runtime {
|
||||
Runtime::new().unwrap()
|
||||
fn rt() -> runtime::Runtime {
|
||||
runtime::Runtime::new().unwrap()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
|
||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn no_runtime_panics_creating_signals() {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
use tokio::sync::Barrier;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
fn is_error<T: std::error::Error + Send + Sync>() {}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
use tokio::sync::mpsc;
|
||||
@@ -88,7 +88,7 @@ async fn reserve_disarm() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[cfg(feature = "full")]
|
||||
#[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(feature = "full")]
|
||||
#[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(feature = "full")]
|
||||
#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads
|
||||
fn blocking_recv() {
|
||||
let (tx, mut rx) = mpsc::channel::<u8>(1);
|
||||
|
||||
@@ -478,7 +478,7 @@ async fn blocking_recv_async() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "full")]
|
||||
#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads
|
||||
fn blocking_send() {
|
||||
let (tx, mut rx) = mpsc::channel::<u8>(1);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
use tokio::sync::Notify;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))]
|
||||
|
||||
use std::error::Error;
|
||||
use tokio::{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||
use tokio::test as maybe_tokio_test;
|
||||
|
||||
use std::task::Poll;
|
||||
@@ -172,7 +172,7 @@ async fn write_order() {
|
||||
}
|
||||
|
||||
// A single RwLock is contested by tasks in multiple threads
|
||||
#[cfg(feature = "full")]
|
||||
#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 8)]
|
||||
async fn multithreaded() {
|
||||
use futures::stream::{self, StreamExt};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "sync")]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||
|
||||
use tokio::sync::watch;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::thread::sleep;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads
|
||||
|
||||
use tokio::{runtime, task};
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
@@ -6,14 +6,19 @@ use futures::{
|
||||
FutureExt,
|
||||
};
|
||||
|
||||
use tokio::runtime::{self, Runtime};
|
||||
use tokio::runtime;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tokio::task::{self, LocalSet};
|
||||
use tokio::time;
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
use std::cell::Cell;
|
||||
use std::sync::atomic::Ordering::{self, SeqCst};
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::time::Duration;
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
@@ -25,6 +30,7 @@ async fn local_basic_scheduler() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn local_threadpool() {
|
||||
thread_local! {
|
||||
@@ -45,6 +51,7 @@ async fn local_threadpool() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn localset_future_threadpool() {
|
||||
thread_local! {
|
||||
@@ -60,6 +67,7 @@ async fn localset_future_threadpool() {
|
||||
local.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn localset_future_timers() {
|
||||
static RAN1: AtomicBool = AtomicBool::new(false);
|
||||
@@ -104,6 +112,7 @@ async fn localset_future_drives_all_local_futs() {
|
||||
assert!(RAN3.load(Ordering::SeqCst));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn local_threadpool_timer() {
|
||||
// This test ensures that runtime services like the timer are properly
|
||||
@@ -127,6 +136,7 @@ async fn local_threadpool_timer() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
|
||||
#[test]
|
||||
// This will panic, since the thread that calls `block_on` cannot use
|
||||
// in-place blocking inside of `block_on`.
|
||||
@@ -153,6 +163,7 @@ fn local_threadpool_blocking_in_place() {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn local_threadpool_blocking_run() {
|
||||
thread_local! {
|
||||
@@ -181,6 +192,7 @@ async fn local_threadpool_blocking_run() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn all_spawns_are_local() {
|
||||
use futures::future;
|
||||
@@ -207,6 +219,7 @@ async fn all_spawns_are_local() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn nested_spawn_is_local() {
|
||||
thread_local! {
|
||||
@@ -242,6 +255,7 @@ async fn nested_spawn_is_local() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
|
||||
#[test]
|
||||
fn join_local_future_elsewhere() {
|
||||
thread_local! {
|
||||
@@ -355,6 +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 = "`unwrap()` in `with_timeout()` panics on Wasi"
|
||||
)]
|
||||
#[test]
|
||||
fn drop_cancels_remote_tasks() {
|
||||
// This test reproduces issue #1885.
|
||||
@@ -377,6 +395,10 @@ fn drop_cancels_remote_tasks() {
|
||||
});
|
||||
}
|
||||
|
||||
#[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.
|
||||
@@ -398,6 +420,7 @@ fn local_tasks_wake_join_all() {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
|
||||
#[test]
|
||||
fn local_tasks_are_polled_after_tick() {
|
||||
// This test depends on timing, so we run it up to five times.
|
||||
@@ -414,6 +437,7 @@ fn local_tasks_are_polled_after_tick() {
|
||||
local_tasks_are_polled_after_tick_inner();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn local_tasks_are_polled_after_tick_inner() {
|
||||
// Reproduces issues #1899 and #1900
|
||||
@@ -540,7 +564,7 @@ mod unstable {
|
||||
}
|
||||
}
|
||||
|
||||
fn rt() -> Runtime {
|
||||
fn rt() -> runtime::Runtime {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use std::io::{Error, ErrorKind, Result};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use std::io::Read;
|
||||
use std::io::Result;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use std::time::Duration;
|
||||
use tokio::net::TcpSocket;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use std::io::Result;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind
|
||||
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
|
||||
|
||||
use futures::future;
|
||||
use std::error::Error;
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
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 {
|
||||
|
||||
@@ -5,6 +5,7 @@ use tokio::time::*;
|
||||
|
||||
use std::sync::mpsc;
|
||||
|
||||
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] // Wasi doesn't support threads
|
||||
#[test]
|
||||
fn timer_with_threaded_runtime() {
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
@@ -168,6 +168,7 @@ async fn reset_sleep_to_past() {
|
||||
assert_ready!(sleep.poll());
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn creating_sleep_outside_of_context() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user