mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
wasm: support the wasm32-unknown-emscripten target (#8281)
This commit is contained in:
@@ -19,6 +19,8 @@ env:
|
|||||||
rust_nightly: nightly-2025-10-12
|
rust_nightly: nightly-2025-10-12
|
||||||
# Pin a specific miri version
|
# Pin a specific miri version
|
||||||
rust_miri_nightly: nightly-2026-06-29
|
rust_miri_nightly: nightly-2026-06-29
|
||||||
|
rust_emscripten_nightly: nightly-2026-08-17
|
||||||
|
emsdk_version: '6.0.8'
|
||||||
rust_clippy: '1.88'
|
rust_clippy: '1.88'
|
||||||
# When updating this, also update:
|
# When updating this, also update:
|
||||||
# - README.md
|
# - README.md
|
||||||
@@ -1193,6 +1195,59 @@ jobs:
|
|||||||
RUSTFLAGS: --cfg tokio_unstable
|
RUSTFLAGS: --cfg tokio_unstable
|
||||||
CARGO_TARGET_WASM32_WASIP2_RUNNER: wasmtime run -Sinherit-network
|
CARGO_TARGET_WASM32_WASIP2_RUNNER: wasmtime run -Sinherit-network
|
||||||
|
|
||||||
|
wasm32-unknown-emscripten:
|
||||||
|
name: test tokio for wasm32-unknown-emscripten
|
||||||
|
needs: basics
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- name: Install Rust ${{ env.rust_stable }}
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: ${{ env.rust_stable }}
|
||||||
|
targets: wasm32-unknown-emscripten
|
||||||
|
|
||||||
|
- name: Install Emscripten
|
||||||
|
uses: mymindstorm/setup-emsdk@v14
|
||||||
|
with:
|
||||||
|
version: ${{ env.emsdk_version }}
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 26
|
||||||
|
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
|
- name: Install cargo-hack
|
||||||
|
uses: taiki-e/install-action@v2
|
||||||
|
with:
|
||||||
|
tool: cargo-hack
|
||||||
|
|
||||||
|
- name: Check tokio feature matrix for emscripten
|
||||||
|
run: cargo hack check -p tokio --each-feature --exclude-features full,net,process,signal,rt-multi-thread,io-uring,taskdump,schedule-latency --target wasm32-unknown-emscripten
|
||||||
|
working-directory: tokio
|
||||||
|
|
||||||
|
- name: Test tokio for emscripten
|
||||||
|
run: cargo test -p tokio --target wasm32-unknown-emscripten --features "rt,time,sync,macros,fs,io-util,io-std,test-util" --tests
|
||||||
|
working-directory: tokio
|
||||||
|
env:
|
||||||
|
CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER: node
|
||||||
|
RUSTFLAGS: "-Dwarnings -Clink-args=-sALLOW_MEMORY_GROWTH=1 -Clink-args=-sEXIT_RUNTIME=1 -Clink-args=-sSTACK_SIZE=1048576"
|
||||||
|
|
||||||
|
- name: Install Rust ${{ env.rust_emscripten_nightly }}
|
||||||
|
uses: dtolnay/rust-toolchain@nightly
|
||||||
|
with:
|
||||||
|
toolchain: ${{ env.rust_emscripten_nightly }}
|
||||||
|
targets: wasm32-unknown-emscripten
|
||||||
|
components: rust-src
|
||||||
|
|
||||||
|
- name: Test tokio multi-thread runtime for emscripten (pthreads)
|
||||||
|
run: cargo +${{ env.rust_emscripten_nightly }} test -Zbuild-std=std,panic_abort -p tokio --target wasm32-unknown-emscripten --features "rt,rt-multi-thread,time,sync,macros" --test rt_multi_thread_emscripten
|
||||||
|
working-directory: tokio
|
||||||
|
env:
|
||||||
|
CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER: node
|
||||||
|
RUSTFLAGS: "-Dwarnings -Ctarget-feature=+atomics,+bulk-memory,+mutable-globals -Clink-args=-pthread -Clink-args=-sPTHREAD_POOL_SIZE=8 -Clink-args=-sINITIAL_MEMORY=134217728 -Clink-args=-sEXIT_RUNTIME=1 -Clink-args=-sSTACK_SIZE=1048576"
|
||||||
|
|
||||||
check-external-types:
|
check-external-types:
|
||||||
name: check-external-types (${{ matrix.os }})
|
name: check-external-types (${{ matrix.os }})
|
||||||
needs: basics
|
needs: basics
|
||||||
|
|||||||
+5
-1
@@ -1,4 +1,4 @@
|
|||||||
327
|
331
|
||||||
&
|
&
|
||||||
+
|
+
|
||||||
<
|
<
|
||||||
@@ -106,6 +106,8 @@ dns
|
|||||||
DNS
|
DNS
|
||||||
DoS
|
DoS
|
||||||
dwOpenMode
|
dwOpenMode
|
||||||
|
Emscripten
|
||||||
|
Emscripten's
|
||||||
endian
|
endian
|
||||||
enqueue
|
enqueue
|
||||||
enqueued
|
enqueued
|
||||||
@@ -213,6 +215,7 @@ plaintext
|
|||||||
poller
|
poller
|
||||||
POSIX
|
POSIX
|
||||||
proxied
|
proxied
|
||||||
|
pthreads
|
||||||
qos
|
qos
|
||||||
RAII
|
RAII
|
||||||
RCU
|
RCU
|
||||||
@@ -323,6 +326,7 @@ Wakers
|
|||||||
wakeup
|
wakeup
|
||||||
wakeups
|
wakeups
|
||||||
WASI
|
WASI
|
||||||
|
Wasm
|
||||||
watchOS
|
watchOS
|
||||||
workstealing
|
workstealing
|
||||||
ZST
|
ZST
|
||||||
|
|||||||
+10
-4
@@ -101,7 +101,7 @@ bytes = { version = "1.2.1", optional = true }
|
|||||||
mio = { version = "1.2.0", optional = true, default-features = false }
|
mio = { version = "1.2.0", optional = true, default-features = false }
|
||||||
parking_lot = { version = "0.12.0", optional = true }
|
parking_lot = { version = "0.12.0", optional = true }
|
||||||
|
|
||||||
[target.'cfg(any(not(target_family = "wasm"), all(target_os = "wasi", not(target_env = "p1"))))'.dependencies]
|
[target.'cfg(any(not(target_family = "wasm"), target_os = "emscripten", all(target_os = "wasi", not(target_env = "p1"))))'.dependencies]
|
||||||
socket2 = { version = "0.6.3", optional = true, features = ["all"] }
|
socket2 = { version = "0.6.3", optional = true, features = ["all"] }
|
||||||
|
|
||||||
# Currently unstable. The API exposed by these features may be broken at any time.
|
# Currently unstable. The API exposed by these features may be broken at any time.
|
||||||
@@ -130,6 +130,8 @@ libc = { version = "0.2.168", optional = true }
|
|||||||
|
|
||||||
[target.'cfg(unix)'.dev-dependencies]
|
[target.'cfg(unix)'.dev-dependencies]
|
||||||
libc = { version = "0.2.168" }
|
libc = { version = "0.2.168" }
|
||||||
|
|
||||||
|
[target.'cfg(all(unix, not(target_os = "emscripten")))'.dev-dependencies]
|
||||||
nix = { version = "0.31.0", default-features = false, features = ["aio", "fs", "socket"] }
|
nix = { version = "0.31.0", default-features = false, features = ["aio", "fs", "socket"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.windows-sys]
|
[target.'cfg(windows)'.dependencies.windows-sys]
|
||||||
@@ -146,22 +148,26 @@ features = [
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio-test = "0.4.0"
|
tokio-test = "0.4.0"
|
||||||
tokio-stream = "0.1"
|
tokio-stream = "0.1"
|
||||||
tokio-util = { version = "0.7", features = ["rt"] }
|
|
||||||
futures = { version = "0.3.0", features = ["async-await"] }
|
futures = { version = "0.3.0", features = ["async-await"] }
|
||||||
futures-test = "0.3.31"
|
futures-test = "0.3.31"
|
||||||
mockall = "0.13.0"
|
mockall = "0.13.0"
|
||||||
async-stream = "0.3"
|
async-stream = "0.3"
|
||||||
futures-concurrency = "7.6.3"
|
futures-concurrency = "7.6.3"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_os = "emscripten"))'.dev-dependencies]
|
||||||
|
tokio-util = { version = "0.7", features = ["rt"] }
|
||||||
|
|
||||||
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
|
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
|
||||||
socket2 = "0.6.0"
|
socket2 = "0.6.0"
|
||||||
tempfile = "3.1.0"
|
|
||||||
proptest = "1"
|
proptest = "1"
|
||||||
|
|
||||||
|
[target.'cfg(any(not(target_family = "wasm"), target_os = "emscripten"))'.dev-dependencies]
|
||||||
|
tempfile = "3.1.0"
|
||||||
|
|
||||||
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies]
|
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies]
|
||||||
rand = "0.9"
|
rand = "0.9"
|
||||||
|
|
||||||
[target.'cfg(all(target_family = "wasm", not(target_os = "wasi")))'.dev-dependencies]
|
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3.0"
|
wasm-bindgen-test = "0.3.0"
|
||||||
|
|
||||||
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
|
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
|
||||||
|
|||||||
@@ -1,12 +1,42 @@
|
|||||||
cfg_rt! {
|
cfg_rt! {
|
||||||
|
#[cfg(any(not(target_os = "emscripten"), target_feature = "atomics"))]
|
||||||
pub(crate) use crate::runtime::spawn_blocking;
|
pub(crate) use crate::runtime::spawn_blocking;
|
||||||
|
|
||||||
cfg_fs! {
|
cfg_fs! {
|
||||||
|
#[cfg(any(not(target_os = "emscripten"), target_feature = "atomics"))]
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub(crate) use crate::runtime::spawn_mandatory_blocking;
|
pub(crate) use crate::runtime::spawn_mandatory_blocking;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(not(target_os = "emscripten"), target_feature = "atomics"))]
|
||||||
pub(crate) use crate::task::JoinHandle;
|
pub(crate) use crate::task::JoinHandle;
|
||||||
|
|
||||||
|
// Non-pthread emscripten has no blocking pool, and the `std` calls behind
|
||||||
|
// `fs` and `io-std` complete synchronously there, so this internal shim
|
||||||
|
// runs the closure inline and hands back an already-completed future. The
|
||||||
|
// public `task::spawn_blocking` is not routed through here and keeps its
|
||||||
|
// native semantics. Pthread builds (`+atomics`) use the native pool.
|
||||||
|
#[cfg(all(target_os = "emscripten", not(target_feature = "atomics")))]
|
||||||
|
pub(crate) type JoinHandle<T> = std::future::Ready<Result<T, crate::task::JoinError>>;
|
||||||
|
|
||||||
|
#[cfg(all(target_os = "emscripten", not(target_feature = "atomics")))]
|
||||||
|
pub(crate) fn spawn_blocking<F, R>(f: F) -> JoinHandle<R>
|
||||||
|
where
|
||||||
|
F: FnOnce() -> R + Send + 'static,
|
||||||
|
R: Send + 'static,
|
||||||
|
{
|
||||||
|
std::future::ready(Ok(f()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(target_os = "emscripten", not(target_feature = "atomics"), feature = "fs"))]
|
||||||
|
#[allow(dead_code)] // unit tests replace this with the `fs::mocks` version
|
||||||
|
pub(crate) fn spawn_mandatory_blocking<F, R>(f: F) -> Option<JoinHandle<R>>
|
||||||
|
where
|
||||||
|
F: FnOnce() -> R + Send + 'static,
|
||||||
|
R: Send + 'static,
|
||||||
|
{
|
||||||
|
Some(spawn_blocking(f))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_not_rt! {
|
cfg_not_rt! {
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(not(loom))]
|
#[cfg(not(loom))]
|
||||||
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::io::blocking::DEFAULT_MAX_BUF_SIZE;
|
use crate::io::blocking::DEFAULT_MAX_BUF_SIZE;
|
||||||
use crate::io::AsyncWriteExt;
|
use crate::io::AsyncWriteExt;
|
||||||
|
|||||||
+55
-17
@@ -424,8 +424,11 @@
|
|||||||
//!
|
//!
|
||||||
//! ## `WASM` support
|
//! ## `WASM` support
|
||||||
//!
|
//!
|
||||||
//! Tokio has some limited support for the `WASM` platform. Without the
|
//! Tokio has some limited support for Wasm platforms.
|
||||||
//! `tokio_unstable` flag, the following features are supported:
|
//!
|
||||||
|
//! Many of Tokio's feature flags are restricted on Wasm, and unsupported
|
||||||
|
//! combinations of feature flags will fail to build. However, all Wasm targets
|
||||||
|
//! can be built with the following features:
|
||||||
//!
|
//!
|
||||||
//! * `sync`
|
//! * `sync`
|
||||||
//! * `macros`
|
//! * `macros`
|
||||||
@@ -434,26 +437,45 @@
|
|||||||
//! * `time`
|
//! * `time`
|
||||||
//!
|
//!
|
||||||
//! Enabling any other feature (including `full`) will cause a compilation
|
//! Enabling any other feature (including `full`) will cause a compilation
|
||||||
//! failure.
|
//! failure. Furthermore, some operations available under these feature flags
|
||||||
|
//! may panic if they are unsupported. For example:
|
||||||
//!
|
//!
|
||||||
//! The `time` module will only work on `WASM` platforms that have support for
|
//! * Using timers will panic on Wasm targets that do not support blocking the
|
||||||
//! timers (e.g. wasm32-wasi). The timing functions will panic if used on a `WASM`
|
//! thread.
|
||||||
//! platform that does not support timers.
|
//! * If the runtime becomes indefinitely idle (e.g., the program triggers a
|
||||||
|
//! deadlock), then this will panic on most Wasm targets.
|
||||||
|
//! * Operations such as `spawn_blocking` that involve spawning threads will
|
||||||
|
//! panic on Wasm targets that do not support threads.
|
||||||
//!
|
//!
|
||||||
//! Note also that if the runtime becomes indefinitely idle, it will panic
|
//! All Wasm targets are still experimental, and breaking behavior changes can
|
||||||
//! immediately instead of blocking forever. On platforms that don't support
|
//! occur in an effort to make Tokio use native Wasm operations. For instance,
|
||||||
//! time, this means that the runtime can never be idle in any way.
|
//! the behavior of timers could be changed from panicking or blocking the
|
||||||
|
//! thread to starting a JavaScript timer. As another example, the
|
||||||
|
//! `spawn_blocking` method could be changed from starting a new thread to
|
||||||
|
//! creating a new cooperatively scheduled context of execution, if the Wasm
|
||||||
|
//! target supports such contexts. As a third example, the `#[tokio::main]` or
|
||||||
|
//! `#[tokio::test]` macros could be changed to work better with the Wasm
|
||||||
|
//! environment.
|
||||||
//!
|
//!
|
||||||
//! ## Unstable `WASM` support
|
//! ### `WASI` support
|
||||||
//!
|
//!
|
||||||
//! Tokio also has unstable support for some additional `WASM` features. This
|
//! The `wasm32-wasip1` and `wasm32-wasip2` targets support the above features.
|
||||||
//! requires the use of the `tokio_unstable` flag.
|
//! Timers work correctly as blocking the thread is supported.
|
||||||
//!
|
//!
|
||||||
//! Using this flag enables the use of `tokio::net` on the wasm32-wasi target.
|
//! Under the `tokio_unstable` flag, these targets support the use
|
||||||
//! However, not all methods are available on the networking types as `WASI`
|
//! of `tokio::net`. On `wasm32-wasip1`, not all methods are available on the
|
||||||
//! currently does not support the creation of new sockets from within `WASM`.
|
//! networking types as this target does not support the creation of new
|
||||||
//! Because of this, sockets must currently be created via the `FromRawFd`
|
//! sockets from within `WASM`. Because of this, sockets must currently be
|
||||||
//! trait.
|
//! created via the `FromRawFd` trait on `wasm32-wasip1`. The `wasm32-wasip2`
|
||||||
|
//! target does not have this limitation.
|
||||||
|
//!
|
||||||
|
//! ### Emscripten support
|
||||||
|
//!
|
||||||
|
//! The `wasm32-unknown-emscripten` target supports the single-threaded runtime
|
||||||
|
//! with the `rt`, `time`, `sync`, `macros`, `fs`, `io-util`, `io-std`, and
|
||||||
|
//! `test-util` features. The `rt-multi-thread` feature is additionally
|
||||||
|
//! supported when building with Emscripten pthreads (`-pthread`). The `net`,
|
||||||
|
//! `process`, and `signal` features are not supported.
|
||||||
|
|
||||||
// Test that pointer width is compatible. This asserts that e.g. usize is at
|
// Test that pointer width is compatible. This asserts that e.g. usize is at
|
||||||
// least 32 bits, which a lot of components in Tokio currently assumes.
|
// least 32 bits, which a lot of components in Tokio currently assumes.
|
||||||
@@ -467,6 +489,7 @@ compile_error! {
|
|||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
not(tokio_unstable),
|
not(tokio_unstable),
|
||||||
target_family = "wasm",
|
target_family = "wasm",
|
||||||
|
not(target_os = "emscripten"),
|
||||||
any(
|
any(
|
||||||
feature = "fs",
|
feature = "fs",
|
||||||
feature = "io-std",
|
feature = "io-std",
|
||||||
@@ -478,6 +501,21 @@ compile_error! {
|
|||||||
))]
|
))]
|
||||||
compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.");
|
compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.");
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
any(feature = "net", feature = "process", feature = "signal")
|
||||||
|
))]
|
||||||
|
compile_error!("Features net,process,signal are not supported on wasm32-unknown-emscripten.");
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt-multi-thread",
|
||||||
|
not(target_feature = "atomics")
|
||||||
|
))]
|
||||||
|
compile_error!(
|
||||||
|
"The `rt-multi-thread` feature on wasm32-unknown-emscripten requires pthreads support (build with `-pthread`)."
|
||||||
|
);
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
tokio_unstable,
|
tokio_unstable,
|
||||||
feature = "taskdump",
|
feature = "taskdump",
|
||||||
|
|||||||
+27
-15
@@ -398,6 +398,7 @@ macro_rules! cfg_process {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "process")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "process")))]
|
||||||
#[cfg(not(loom))]
|
#[cfg(not(loom))]
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_os = "wasi"))]
|
||||||
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
$item
|
$item
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
@@ -405,16 +406,29 @@ macro_rules! cfg_process {
|
|||||||
|
|
||||||
macro_rules! cfg_process_driver {
|
macro_rules! cfg_process_driver {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
#[cfg(unix)]
|
$(
|
||||||
#[cfg(not(loom))]
|
#[cfg(all(
|
||||||
cfg_process! { $($item)* }
|
unix,
|
||||||
|
not(loom),
|
||||||
|
feature = "process",
|
||||||
|
not(target_os = "wasi"),
|
||||||
|
not(target_os = "emscripten"),
|
||||||
|
))]
|
||||||
|
$item
|
||||||
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! cfg_not_process_driver {
|
macro_rules! cfg_not_process_driver {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
$(
|
$(
|
||||||
#[cfg(not(all(unix, not(loom), feature = "process")))]
|
#[cfg(not(all(
|
||||||
|
unix,
|
||||||
|
not(loom),
|
||||||
|
feature = "process",
|
||||||
|
not(target_os = "wasi"),
|
||||||
|
not(target_os = "emscripten"),
|
||||||
|
)))]
|
||||||
$item
|
$item
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
@@ -427,6 +441,7 @@ macro_rules! cfg_signal {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
|
||||||
#[cfg(not(loom))]
|
#[cfg(not(loom))]
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_os = "wasi"))]
|
||||||
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
$item
|
$item
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
@@ -437,6 +452,7 @@ macro_rules! cfg_signal_internal {
|
|||||||
$(
|
$(
|
||||||
#[cfg(any(feature = "signal", all(unix, feature = "process")))]
|
#[cfg(any(feature = "signal", all(unix, feature = "process")))]
|
||||||
#[cfg(not(loom))]
|
#[cfg(not(loom))]
|
||||||
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
$item
|
$item
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
@@ -449,10 +465,15 @@ macro_rules! cfg_signal_internal_and_unix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! cfg_not_signal_internal {
|
macro_rules! cfg_not_signal_internal_and_unix {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
$(
|
$(
|
||||||
#[cfg(any(loom, not(unix), not(any(feature = "signal", all(unix, feature = "process")))))]
|
#[cfg(not(all(
|
||||||
|
unix,
|
||||||
|
any(feature = "signal", all(unix, feature = "process")),
|
||||||
|
not(loom),
|
||||||
|
not(target_os = "emscripten"),
|
||||||
|
)))]
|
||||||
$item
|
$item
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
@@ -712,15 +733,6 @@ macro_rules! cfg_not_wasip1 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! cfg_is_wasm_not_wasi {
|
|
||||||
($($item:item)*) => {
|
|
||||||
$(
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
|
||||||
$item
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Use this macro to provide two different implementations of the same API — one for stable
|
/// Use this macro to provide two different implementations of the same API — one for stable
|
||||||
/// builds and one for unstable builds.
|
/// builds and one for unstable builds.
|
||||||
macro_rules! cfg_metrics_variant {
|
macro_rules! cfg_metrics_variant {
|
||||||
|
|||||||
@@ -182,7 +182,13 @@ pub(crate) struct Task {
|
|||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub(crate) enum Mandatory {
|
pub(crate) enum Mandatory {
|
||||||
#[cfg_attr(not(feature = "fs"), allow(dead_code))]
|
#[cfg_attr(
|
||||||
|
any(
|
||||||
|
not(feature = "fs"),
|
||||||
|
all(target_os = "emscripten", not(target_feature = "atomics"))
|
||||||
|
),
|
||||||
|
allow(dead_code)
|
||||||
|
)]
|
||||||
Mandatory,
|
Mandatory,
|
||||||
NonMandatory,
|
NonMandatory,
|
||||||
}
|
}
|
||||||
@@ -246,7 +252,8 @@ where
|
|||||||
cfg_fs! {
|
cfg_fs! {
|
||||||
#[cfg_attr(any(
|
#[cfg_attr(any(
|
||||||
all(loom, not(test)), // the function is covered by loom tests
|
all(loom, not(test)), // the function is covered by loom tests
|
||||||
test
|
test,
|
||||||
|
all(target_os = "emscripten", not(target_feature = "atomics")), // fs uses the inline shim
|
||||||
), allow(dead_code))]
|
), allow(dead_code))]
|
||||||
/// Runs the provided function on an executor dedicated to blocking
|
/// Runs the provided function on an executor dedicated to blocking
|
||||||
/// operations. Tasks will be scheduled as mandatory, meaning they are
|
/// operations. Tasks will be scheduled as mandatory, meaning they are
|
||||||
@@ -385,7 +392,8 @@ impl Spawner {
|
|||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[cfg_attr(any(
|
#[cfg_attr(any(
|
||||||
all(loom, not(test)), // the function is covered by loom tests
|
all(loom, not(test)), // the function is covered by loom tests
|
||||||
test
|
test,
|
||||||
|
all(target_os = "emscripten", not(target_feature = "atomics")), // fs uses the inline shim
|
||||||
), allow(dead_code))]
|
), allow(dead_code))]
|
||||||
pub(crate) fn spawn_mandatory_blocking<F, R>(&self, rt: &Handle, func: F) -> Option<JoinHandle<R>>
|
pub(crate) fn spawn_mandatory_blocking<F, R>(&self, rt: &Handle, func: F) -> Option<JoinHandle<R>>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ cfg_signal_internal_and_unix! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_not_signal_internal! {
|
cfg_not_signal_internal_and_unix! {
|
||||||
pub(crate) type SignalHandle = ();
|
pub(crate) type SignalHandle = ();
|
||||||
|
|
||||||
cfg_io_driver! {
|
cfg_io_driver! {
|
||||||
|
|||||||
@@ -550,6 +550,11 @@ cfg_rt! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg_fs! {
|
cfg_fs! {
|
||||||
|
// Non-pthread emscripten uses the inline shim in `crate::blocking`.
|
||||||
|
#[cfg_attr(
|
||||||
|
all(target_os = "emscripten", not(target_feature = "atomics")),
|
||||||
|
allow(unused_imports)
|
||||||
|
)]
|
||||||
pub(crate) use blocking::spawn_mandatory_blocking;
|
pub(crate) use blocking::spawn_mandatory_blocking;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#![cfg(not(target_os = "wasi"))]
|
#![cfg(all(not(target_os = "wasi"), not(target_os = "emscripten")))]
|
||||||
|
|
||||||
use std::{task::Context, time::Duration};
|
use std::{task::Context, time::Duration};
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ impl AssertSync for AtomicWaker {}
|
|||||||
impl AssertSend for Waker {}
|
impl AssertSend for Waker {}
|
||||||
impl AssertSync for Waker {}
|
impl AssertSync for Waker {}
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::future::Future;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::task::{Context, RawWaker, RawWakerVTable, Waker};
|
use std::task::{Context, RawWaker, RawWakerVTable, Waker};
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use tokio_test::*;
|
|||||||
|
|
||||||
const MAX_PERMITS: usize = crate::sync::Semaphore::MAX_PERMITS;
|
const MAX_PERMITS: usize = crate::sync::Semaphore::MAX_PERMITS;
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ cfg_coop! {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
fn get() -> Budget {
|
fn get() -> Budget {
|
||||||
|
|||||||
@@ -1276,7 +1276,7 @@ impl LocalState {
|
|||||||
// ensure they are on the same thread that owns the `LocalSet`.
|
// ensure they are on the same thread that owns the `LocalSet`.
|
||||||
unsafe impl Send for LocalState {}
|
unsafe impl Send for LocalState {}
|
||||||
|
|
||||||
#[cfg(all(test, not(loom)))]
|
#[cfg(all(test, not(loom), not(target_os = "emscripten")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ unsafe impl<T> linked_list::Link for ListEntry<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(test, not(loom)))]
|
#[cfg(all(test, not(loom), not(target_os = "emscripten")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::runtime::Builder;
|
use crate::runtime::Builder;
|
||||||
use crate::task::JoinSet;
|
use crate::task::JoinSet;
|
||||||
|
|||||||
+13
-1
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi does not support file operations
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "fs"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
@@ -16,6 +24,10 @@ async fn path_read_write() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[cfg_attr(
|
||||||
|
target_os = "emscripten",
|
||||||
|
ignore = "emscripten libc does not implement dup()/try_clone()"
|
||||||
|
)]
|
||||||
async fn try_clone_should_preserve_max_buf_size() {
|
async fn try_clone_should_preserve_max_buf_size() {
|
||||||
let buf_size = 128;
|
let buf_size = 128;
|
||||||
let temp = tempdir();
|
let temp = tempdir();
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|||||||
+13
-1
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio_test::{assert_err, assert_ok};
|
use tokio_test::{assert_err, assert_ok};
|
||||||
|
|||||||
+21
-1
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@@ -99,6 +111,10 @@ async fn rewind_seek_position() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[cfg_attr(
|
||||||
|
target_os = "emscripten",
|
||||||
|
ignore = "inline-fs shim does not insert cooperative yield points"
|
||||||
|
)]
|
||||||
async fn coop() {
|
async fn coop() {
|
||||||
let mut tempfile = tempfile();
|
let mut tempfile = tempfile();
|
||||||
tempfile.write_all(HELLO).unwrap();
|
tempfile.write_all(HELLO).unwrap();
|
||||||
@@ -124,6 +140,10 @@ async fn coop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[cfg_attr(
|
||||||
|
target_os = "emscripten",
|
||||||
|
ignore = "emscripten libc does not implement dup()/try_clone()"
|
||||||
|
)]
|
||||||
async fn write_to_clone() {
|
async fn write_to_clone() {
|
||||||
let tempfile = tempfile();
|
let tempfile = tempfile();
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
@@ -8,6 +20,7 @@ use tempfile::tempdir;
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
||||||
|
#[cfg_attr(target_os = "emscripten", ignore = "MEMFS rejects link() with EMLINK")]
|
||||||
async fn test_hard_link() {
|
async fn test_hard_link() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let src = dir.path().join("src.txt");
|
let src = dir.path().join("src.txt");
|
||||||
@@ -63,6 +76,7 @@ async fn test_symlink() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
||||||
|
#[cfg_attr(target_os = "emscripten", ignore = "MEMFS rejects link() with EMLINK")]
|
||||||
async fn test_hard_link_error_source_not_found() {
|
async fn test_hard_link_error_source_not_found() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let src = dir.path().join("nonexistent.txt");
|
let src = dir.path().join("nonexistent.txt");
|
||||||
@@ -72,6 +86,7 @@ async fn test_hard_link_error_source_not_found() {
|
|||||||
assert_eq!(err.kind(), std::io::ErrorKind::NotFound);
|
assert_eq!(err.kind(), std::io::ErrorKind::NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On emscripten MEMFS reports EEXIST before its unconditional link() EMLINK.
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
||||||
async fn test_hard_link_error_destination_already_exists() {
|
async fn test_hard_link_error_destination_already_exists() {
|
||||||
@@ -92,6 +107,7 @@ async fn test_hard_link_error_destination_already_exists() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
#[cfg_attr(miri, ignore)] // No `linkat` in miri.
|
||||||
|
#[cfg_attr(target_os = "emscripten", ignore = "MEMFS rejects link() with EMLINK")]
|
||||||
async fn test_hard_link_error_source_is_directory() {
|
async fn test_hard_link_error_source_is_directory() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let src_dir = dir.path().join("src_directory");
|
let src_dir = dir.path().join("src_directory");
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|||||||
+13
-1
@@ -1,5 +1,17 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "fs",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
not(target_os = "wasi")
|
||||||
|
))] // WASI does not support all fs operations
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::AsyncRead;
|
use tokio::io::AsyncRead;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
// https://github.com/rust-lang/futures-rs/blob/1803948ff091b4eabf7f3bf39e16bbbdefca5cc8/futures/tests/io_buf_reader.rs
|
// https://github.com/rust-lang/futures-rs/blob/1803948ff091b4eabf7f3bf39e16bbbdefca5cc8/futures/tests/io_buf_reader.rs
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
// https://github.com/rust-lang/futures-rs/blob/1803948ff091b4eabf7f3bf39e16bbbdefca5cc8/futures/tests/io_buf_writer.rs
|
// https://github.com/rust-lang/futures-rs/blob/1803948ff091b4eabf7f3bf39e16bbbdefca5cc8/futures/tests/io_buf_writer.rs
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use tokio::io::{self, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf};
|
use tokio::io::{self, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf};
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
//! Standard I/O tests for emscripten.
|
||||||
|
//!
|
||||||
|
//! `tokio::io::{stdout, stderr}` round through emscripten's libc to the JS
|
||||||
|
//! `print`/`printErr` hooks; these tests mostly check that writes don't fail —
|
||||||
|
//! observable output verification is left to manual `--nocapture` runs.
|
||||||
|
//!
|
||||||
|
//! `tokio::io::stdin` reads fd 0 synchronously in emscripten, so this only
|
||||||
|
//! completes when stdin is non-interactive (EOF), as under CI where
|
||||||
|
//! the runner's stdin is `/dev/null`. The contract worth pinning is "a stdin
|
||||||
|
//! read returns rather than deadlocking", not a specific errno.
|
||||||
|
|
||||||
|
#![cfg(all(target_os = "emscripten", feature = "io-std"))]
|
||||||
|
|
||||||
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn stdout_write_completes() {
|
||||||
|
let mut out = tokio::io::stdout();
|
||||||
|
out.write_all(b"hello from stdout\n").await.unwrap();
|
||||||
|
out.flush().await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn stderr_write_completes() {
|
||||||
|
let mut err = tokio::io::stderr();
|
||||||
|
err.write_all(b"hello from stderr\n").await.unwrap();
|
||||||
|
err.flush().await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn stdout_large_multichunk_write_completes() {
|
||||||
|
// Exercises the BufWriter chunking inside `Stdout` (writes larger than
|
||||||
|
// the internal buffer force multiple underlying writes).
|
||||||
|
let mut out = tokio::io::stdout();
|
||||||
|
let data = vec![b'x'; 64 * 1024];
|
||||||
|
out.write_all(&data).await.unwrap();
|
||||||
|
out.flush().await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn stdout_interleaved_writes_complete() {
|
||||||
|
let mut out = tokio::io::stdout();
|
||||||
|
for i in 0..16 {
|
||||||
|
out.write_all(format!("line {i}\n").as_bytes())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
out.flush().await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn stdin_read_does_not_hang() {
|
||||||
|
// The runner detaches stdin onto the null device, so a read must return
|
||||||
|
// promptly (Ok(0) EOF or an I/O error) rather than blocking the host
|
||||||
|
// loop. The runner's watchdog fails the test if this ever deadlocks.
|
||||||
|
let mut stdin = tokio::io::stdin();
|
||||||
|
let mut buf = [0u8; 32];
|
||||||
|
let _ = stdin.read(&mut buf).await;
|
||||||
|
}
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")),
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util",
|
||||||
|
feature = "fs"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{join, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, Join, ReadBuf};
|
use tokio::io::{join, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, Join, ReadBuf};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use std::io::IoSlice;
|
use std::io::IoSlice;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi does not support panic recovery
|
||||||
|
all(target_os = "emscripten", feature = "io-util")
|
||||||
|
))]
|
||||||
#![cfg(panic = "unwind")]
|
#![cfg(panic = "unwind")]
|
||||||
|
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
@@ -42,7 +45,7 @@ impl AsyncWrite for RW {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(all(unix, not(target_os = "emscripten")))]
|
||||||
mod unix {
|
mod unix {
|
||||||
use std::os::unix::prelude::{AsRawFd, RawFd};
|
use std::os::unix::prelude::{AsRawFd, RawFd};
|
||||||
|
|
||||||
@@ -168,7 +171,7 @@ fn new_unsplit_zero_capacity_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(all(unix, not(target_os = "emscripten")))]
|
||||||
fn async_fd_new_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn async_fd_new_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
use tokio::io::unix::AsyncFd;
|
use tokio::io::unix::AsyncFd;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
@@ -190,7 +193,7 @@ fn async_fd_new_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(all(unix, not(target_os = "emscripten")))]
|
||||||
fn async_fd_with_interest_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn async_fd_with_interest_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
use tokio::io::unix::AsyncFd;
|
use tokio::io::unix::AsyncFd;
|
||||||
use tokio::io::Interest;
|
use tokio::io::Interest;
|
||||||
@@ -213,7 +216,7 @@ fn async_fd_with_interest_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(all(unix, not(target_os = "emscripten")))]
|
||||||
fn async_fd_try_new_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn async_fd_try_new_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
use tokio::io::unix::AsyncFd;
|
use tokio::io::unix::AsyncFd;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
@@ -235,7 +238,7 @@ fn async_fd_try_new_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(all(unix, not(target_os = "emscripten")))]
|
||||||
fn async_fd_try_with_interest_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn async_fd_try_with_interest_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
use tokio::io::unix::AsyncFd;
|
use tokio::io::unix::AsyncFd;
|
||||||
use tokio::io::Interest;
|
use tokio::io::Interest;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi does not support panic recovery
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf};
|
use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf};
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf};
|
use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf};
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use tokio::io::{AsyncBufReadExt, BufReader, Error};
|
use tokio::io::{AsyncBufReadExt, BufReader, Error};
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(miri)))]
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(miri)),
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi does not support panic recovery
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{
|
use tokio::io::{
|
||||||
split, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf, ReadHalf, WriteHalf,
|
split, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf, ReadHalf, WriteHalf,
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi does not support panic recovery
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncSeekExt};
|
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncSeekExt};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
use tokio_test::{assert_err, assert_ok};
|
use tokio_test::{assert_err, assert_ok};
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "io-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi doesn't support panic recovery
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "macros", feature = "time")
|
||||||
|
))]
|
||||||
#![cfg(panic = "unwind")]
|
#![cfg(panic = "unwind")]
|
||||||
|
|
||||||
struct PanicsOnDrop;
|
struct PanicsOnDrop;
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
#![allow(clippy::disallowed_names)]
|
#![allow(clippy::disallowed_names)]
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
use tokio::sync::{oneshot, Semaphore};
|
use tokio::sync::{oneshot, Semaphore};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#![cfg(feature = "macros")]
|
#![cfg(feature = "macros")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
async fn one() {}
|
async fn one() {}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#![cfg(feature = "macros")]
|
#![cfg(feature = "macros")]
|
||||||
#![allow(clippy::disallowed_names)]
|
#![allow(clippy::disallowed_names)]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ use std::{convert::Infallible, sync::Arc};
|
|||||||
use tokio::sync::{oneshot, Semaphore};
|
use tokio::sync::{oneshot, Semaphore};
|
||||||
use tokio_test::{assert_pending, assert_ready, task};
|
use tokio_test::{assert_pending, assert_ready, task};
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
#[maybe_tokio_test]
|
#[maybe_tokio_test]
|
||||||
|
|||||||
+16
-4
@@ -1,5 +1,8 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "macros")
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::runtime::{self, Runtime};
|
use tokio::runtime::{self, Runtime};
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
@@ -249,7 +252,10 @@ fn spawn_two() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_os = "wasi", ignore = "WASI: std::thread::spawn not supported")]
|
#[cfg_attr(
|
||||||
|
target_family = "wasm",
|
||||||
|
ignore = "wasm targets do not support std::thread::spawn"
|
||||||
|
)]
|
||||||
#[test]
|
#[test]
|
||||||
fn spawn_remote() {
|
fn spawn_remote() {
|
||||||
let rt = rt();
|
let rt = rt();
|
||||||
@@ -346,7 +352,10 @@ mod unstable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
|
#[cfg_attr(
|
||||||
|
target_family = "wasm",
|
||||||
|
ignore = "wasm targets do not support std::thread::spawn"
|
||||||
|
)]
|
||||||
fn spawns_do_nothing() {
|
fn spawns_do_nothing() {
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -375,7 +384,10 @@ mod unstable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
|
#[cfg_attr(
|
||||||
|
target_family = "wasm",
|
||||||
|
ignore = "wasm targets do not support std::thread::spawn"
|
||||||
|
)]
|
||||||
fn shutdown_all_concurrent_block_on() {
|
fn shutdown_all_concurrent_block_on() {
|
||||||
const N: usize = 2;
|
const N: usize = 2;
|
||||||
use std::sync::{mpsc, Arc};
|
use std::sync::{mpsc, Arc};
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "macros")
|
||||||
|
))]
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#![warn(rust_2018_idioms)]
|
||||||
|
#![cfg(all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt-multi-thread",
|
||||||
|
feature = "macros"
|
||||||
|
))]
|
||||||
|
|
||||||
|
//! Multi-thread runtime tests for `wasm32-unknown-emscripten` built with
|
||||||
|
//! pthreads (`-pthread`).
|
||||||
|
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::sync::{Arc, Barrier};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_on_multi_thread() {
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(2)
|
||||||
|
.enable_time()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let out = rt.block_on(async {
|
||||||
|
let jh = tokio::spawn(async {
|
||||||
|
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||||
|
"hello"
|
||||||
|
});
|
||||||
|
jh.await.unwrap()
|
||||||
|
});
|
||||||
|
assert_eq!(out, "hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn spawn_blocking_runs_in_parallel() {
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(2)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Both closures must be running concurrently for the barrier to release.
|
||||||
|
let barrier = Arc::new(Barrier::new(2));
|
||||||
|
rt.block_on(async {
|
||||||
|
let a = tokio::task::spawn_blocking({
|
||||||
|
let barrier = barrier.clone();
|
||||||
|
move || {
|
||||||
|
barrier.wait();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let b = tokio::task::spawn_blocking(move || {
|
||||||
|
barrier.wait();
|
||||||
|
});
|
||||||
|
a.await.unwrap();
|
||||||
|
b.await.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn macro_multi_thread() {
|
||||||
|
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
|
let mut handles = Vec::new();
|
||||||
|
for _ in 0..8 {
|
||||||
|
handles.push(tokio::spawn(async {
|
||||||
|
tokio::task::yield_now().await;
|
||||||
|
COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
for handle in handles {
|
||||||
|
handle.await.unwrap();
|
||||||
|
}
|
||||||
|
assert_eq!(COUNT.load(Ordering::Relaxed), 8);
|
||||||
|
}
|
||||||
+12
-2
@@ -1,11 +1,16 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "macros")
|
||||||
|
))]
|
||||||
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
|
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
|
||||||
#![cfg(panic = "unwind")]
|
#![cfg(panic = "unwind")]
|
||||||
|
|
||||||
use futures::future;
|
use futures::future;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use tokio::runtime::{Builder, Handle, Runtime};
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
|
use tokio::runtime::Builder;
|
||||||
|
use tokio::runtime::{Handle, Runtime};
|
||||||
|
|
||||||
mod support {
|
mod support {
|
||||||
pub mod panic;
|
pub mod panic;
|
||||||
@@ -47,6 +52,7 @@ fn into_panic_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
fn builder_worker_threads_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn builder_worker_threads_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
let panic_location_file = test_panic(|| {
|
let panic_location_file = test_panic(|| {
|
||||||
let _ = Builder::new_multi_thread().worker_threads(0).build();
|
let _ = Builder::new_multi_thread().worker_threads(0).build();
|
||||||
@@ -59,6 +65,7 @@ fn builder_worker_threads_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
fn builder_max_blocking_threads_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn builder_max_blocking_threads_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
let panic_location_file = test_panic(|| {
|
let panic_location_file = test_panic(|| {
|
||||||
let _ = Builder::new_multi_thread().max_blocking_threads(0).build();
|
let _ = Builder::new_multi_thread().max_blocking_threads(0).build();
|
||||||
@@ -71,6 +78,7 @@ fn builder_max_blocking_threads_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
fn builder_global_queue_interval_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn builder_global_queue_interval_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
let panic_location_file = test_panic(|| {
|
let panic_location_file = test_panic(|| {
|
||||||
let _ = Builder::new_multi_thread().global_queue_interval(0).build();
|
let _ = Builder::new_multi_thread().global_queue_interval(0).build();
|
||||||
@@ -83,6 +91,7 @@ fn builder_global_queue_interval_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
fn builder_event_interval_interval_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn builder_event_interval_interval_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
let panic_location_file = test_panic(|| {
|
let panic_location_file = test_panic(|| {
|
||||||
let _ = Builder::new_multi_thread().event_interval(0).build();
|
let _ = Builder::new_multi_thread().event_interval(0).build();
|
||||||
@@ -95,6 +104,7 @@ fn builder_event_interval_interval_panic_caller() -> Result<(), Box<dyn Error>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
fn builder_name_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn builder_name_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
let panic_location_file = test_panic(|| {
|
let panic_location_file = test_panic(|| {
|
||||||
let _ = Builder::new_multi_thread().name(" ").build();
|
let _ = Builder::new_multi_thread().name(" ").build();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(feature = "full", all(target_os = "emscripten", feature = "rt")))]
|
||||||
#![cfg(not(miri))] // No socket in miri.
|
#![cfg(not(miri))] // No socket in miri.
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ fn rt() -> tokio::runtime::Runtime {
|
|||||||
Builder::new_current_thread().enable_all().build().unwrap()
|
Builder::new_current_thread().enable_all().build().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))] // needs net (TcpListener)
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_rt_shutdown_err() {
|
fn test_is_rt_shutdown_err() {
|
||||||
let rt1 = rt();
|
let rt1 = rt();
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "test-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::time::{Duration, Instant};
|
use tokio::time::{Duration, Instant};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use tokio::sync::Barrier;
|
use tokio::sync::Barrier;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
@@ -563,7 +563,7 @@ fn sender_len() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
fn sender_len_random() {
|
fn sender_len_random() {
|
||||||
let (tx, mut rx1) = broadcast::channel(16);
|
let (tx, mut rx1) = broadcast::channel(16);
|
||||||
let mut rx2 = tx.subscribe();
|
let mut rx2 = tx.subscribe();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use tokio::sync::broadcast::{self, channel};
|
use tokio::sync::broadcast::{self, channel};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
fn is_error<T: std::error::Error + Send + Sync>() {}
|
fn is_error<T: std::error::Error + Send + Sync>() {}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use tokio::sync::Notify;
|
use tokio::sync::Notify;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "test-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::atomic::{AtomicU32, Ordering};
|
use std::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))]
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")),
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "sync")
|
||||||
|
))]
|
||||||
#![cfg(panic = "unwind")]
|
#![cfg(panic = "unwind")]
|
||||||
|
|
||||||
use std::{error::Error, sync::Arc};
|
use std::{error::Error, sync::Arc};
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
|
||||||
|
|
||||||
#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
|
||||||
use tokio::test as maybe_tokio_test;
|
use tokio::test as maybe_tokio_test;
|
||||||
|
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "sync",
|
||||||
|
feature = "macros"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicU32, Ordering},
|
atomic::{AtomicU32, Ordering},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "sync")]
|
#![cfg(feature = "sync")]
|
||||||
|
|
||||||
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
|
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||||
use wasm_bindgen_test::wasm_bindgen_test as test;
|
use wasm_bindgen_test::wasm_bindgen_test as test;
|
||||||
|
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi doesn't support panic recovery
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "time")
|
||||||
|
))]
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
|
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
|
|
||||||
#[cfg(panic = "unwind")]
|
#[cfg(all(panic = "unwind", not(target_family = "wasm")))]
|
||||||
struct PanicOnDrop;
|
struct PanicOnDrop;
|
||||||
|
|
||||||
#[cfg(panic = "unwind")]
|
#[cfg(all(panic = "unwind", not(target_family = "wasm")))]
|
||||||
impl Drop for PanicOnDrop {
|
impl Drop for PanicOnDrop {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
panic!("Well what did you expect would happen...");
|
panic!("Well what did you expect would happen...");
|
||||||
@@ -19,6 +25,7 @@ impl Drop for PanicOnDrop {
|
|||||||
|
|
||||||
/// Checks that a suspended task can be aborted without panicking as reported in
|
/// Checks that a suspended task can be aborted without panicking as reported in
|
||||||
/// issue #3157: <https://github.com/tokio-rs/tokio/issues/3157>.
|
/// issue #3157: <https://github.com/tokio-rs/tokio/issues/3157>.
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_abort_without_panic_3157() {
|
fn test_abort_without_panic_3157() {
|
||||||
let rt = Builder::new_multi_thread()
|
let rt = Builder::new_multi_thread()
|
||||||
@@ -41,6 +48,7 @@ fn test_abort_without_panic_3157() {
|
|||||||
/// Checks that a suspended task can be aborted inside of a current_thread
|
/// Checks that a suspended task can be aborted inside of a current_thread
|
||||||
/// executor without panicking as reported in issue #3662:
|
/// executor without panicking as reported in issue #3662:
|
||||||
/// <https://github.com/tokio-rs/tokio/issues/3662>.
|
/// <https://github.com/tokio-rs/tokio/issues/3662>.
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_abort_without_panic_3662() {
|
fn test_abort_without_panic_3662() {
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
@@ -104,6 +112,7 @@ fn test_abort_without_panic_3662() {
|
|||||||
/// Checks that a suspended LocalSet task can be aborted from a remote thread
|
/// Checks that a suspended LocalSet task can be aborted from a remote thread
|
||||||
/// without panicking and without running the tasks destructor on the wrong thread.
|
/// without panicking and without running the tasks destructor on the wrong thread.
|
||||||
/// <https://github.com/tokio-rs/tokio/issues/3929>
|
/// <https://github.com/tokio-rs/tokio/issues/3929>
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn remote_abort_local_set_3929() {
|
fn remote_abort_local_set_3929() {
|
||||||
struct DropCheck {
|
struct DropCheck {
|
||||||
@@ -147,6 +156,7 @@ fn remote_abort_local_set_3929() {
|
|||||||
|
|
||||||
/// Checks that a suspended task can be aborted even if the `JoinHandle` is immediately dropped.
|
/// Checks that a suspended task can be aborted even if the `JoinHandle` is immediately dropped.
|
||||||
/// issue #3964: <https://github.com/tokio-rs/tokio/issues/3964>.
|
/// issue #3964: <https://github.com/tokio-rs/tokio/issues/3964>.
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_abort_wakes_task_3964() {
|
fn test_abort_wakes_task_3964() {
|
||||||
let rt = Builder::new_current_thread().enable_time().build().unwrap();
|
let rt = Builder::new_current_thread().enable_time().build().unwrap();
|
||||||
@@ -177,8 +187,8 @@ fn test_abort_wakes_task_3964() {
|
|||||||
|
|
||||||
/// Checks that aborting a task whose destructor panics does not allow the
|
/// Checks that aborting a task whose destructor panics does not allow the
|
||||||
/// panic to escape the task.
|
/// panic to escape the task.
|
||||||
|
#[cfg(all(panic = "unwind", not(target_family = "wasm")))]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(panic = "unwind")]
|
|
||||||
fn test_abort_task_that_panics_on_drop_contained() {
|
fn test_abort_task_that_panics_on_drop_contained() {
|
||||||
let rt = Builder::new_current_thread().enable_time().build().unwrap();
|
let rt = Builder::new_current_thread().enable_time().build().unwrap();
|
||||||
|
|
||||||
@@ -201,8 +211,8 @@ fn test_abort_task_that_panics_on_drop_contained() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks that aborting a task whose destructor panics has the expected result.
|
/// Checks that aborting a task whose destructor panics has the expected result.
|
||||||
|
#[cfg(all(panic = "unwind", not(target_family = "wasm")))]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(panic = "unwind")]
|
|
||||||
fn test_abort_task_that_panics_on_drop_returned() {
|
fn test_abort_task_that_panics_on_drop_returned() {
|
||||||
let rt = Builder::new_current_thread().enable_time().build().unwrap();
|
let rt = Builder::new_current_thread().enable_time().build().unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#![cfg(all(target_os = "emscripten", not(target_feature = "atomics")))]
|
||||||
|
|
||||||
|
/// There is no threadpool on a single-threaded JS worker: the public
|
||||||
|
/// `spawn_blocking` is unsupported on non-pthread emscripten, as on the other
|
||||||
|
/// single-threaded wasm targets. `tokio::fs` and
|
||||||
|
/// `tokio::io::{stdin, stdout, stderr}` do not rely on it there — their
|
||||||
|
/// syscalls complete synchronously.
|
||||||
|
#[tokio::test]
|
||||||
|
#[should_panic = "OS can't spawn worker thread"]
|
||||||
|
async fn spawn_blocking_is_unsupported() {
|
||||||
|
let _ = tokio::task::spawn_blocking(|| 42).await;
|
||||||
|
}
|
||||||
+20
-8
@@ -1,10 +1,19 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "sync",
|
||||||
|
feature = "macros"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tokio::task::{self, Id, LocalSet};
|
use tokio::task::{self, Id, LocalSet};
|
||||||
@@ -21,7 +30,7 @@ async fn task_id_spawn() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(any(target_os = "wasi", target_os = "emscripten")))]
|
||||||
#[tokio::test(flavor = "current_thread")]
|
#[tokio::test(flavor = "current_thread")]
|
||||||
async fn task_id_spawn_blocking() {
|
async fn task_id_spawn_blocking() {
|
||||||
task::spawn_blocking(|| println!("task id: {}", task::id()))
|
task::spawn_blocking(|| println!("task id: {}", task::id()))
|
||||||
@@ -38,7 +47,7 @@ async fn task_id_collision_current_thread() {
|
|||||||
assert_ne!(id1.unwrap(), id2.unwrap());
|
assert_ne!(id1.unwrap(), id2.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn task_id_collision_multi_thread() {
|
async fn task_id_collision_multi_thread() {
|
||||||
let handle1 = tokio::spawn(async { task::id() });
|
let handle1 = tokio::spawn(async { task::id() });
|
||||||
@@ -59,7 +68,7 @@ async fn task_ids_match_current_thread() {
|
|||||||
handle.await.unwrap();
|
handle.await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn task_ids_match_multi_thread() {
|
async fn task_ids_match_multi_thread() {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
@@ -72,7 +81,8 @@ async fn task_ids_match_multi_thread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_os = "wasi"))]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[cfg_attr(target_os = "emscripten", tokio::test(flavor = "current_thread"))]
|
||||||
|
#[cfg_attr(not(target_os = "emscripten"), tokio::test(flavor = "multi_thread"))]
|
||||||
async fn task_id_future_destructor_completion() {
|
async fn task_id_future_destructor_completion() {
|
||||||
struct MyFuture {
|
struct MyFuture {
|
||||||
tx: Option<oneshot::Sender<Id>>,
|
tx: Option<oneshot::Sender<Id>>,
|
||||||
@@ -100,7 +110,8 @@ async fn task_id_future_destructor_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_os = "wasi"))]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[cfg_attr(target_os = "emscripten", tokio::test(flavor = "current_thread"))]
|
||||||
|
#[cfg_attr(not(target_os = "emscripten"), tokio::test(flavor = "multi_thread"))]
|
||||||
async fn task_id_future_destructor_abort() {
|
async fn task_id_future_destructor_abort() {
|
||||||
struct MyFuture {
|
struct MyFuture {
|
||||||
tx: Option<oneshot::Sender<Id>>,
|
tx: Option<oneshot::Sender<Id>>,
|
||||||
@@ -205,7 +216,7 @@ fn task_try_id_outside_task() {
|
|||||||
assert_eq!(None, task::try_id());
|
assert_eq!(None, task::try_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn task_try_id_inside_block_on() {
|
fn task_try_id_inside_block_on() {
|
||||||
let rt = Runtime::new().unwrap();
|
let rt = Runtime::new().unwrap();
|
||||||
@@ -248,7 +259,7 @@ async fn task_id_nested_spawn_local() {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn task_id_block_in_place_block_on_spawn() {
|
async fn task_id_block_in_place_block_on_spawn() {
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
@@ -283,6 +294,7 @@ fn task_id_outside_task_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(not(panic = "unwind"), ignore)]
|
#[cfg_attr(not(panic = "unwind"), ignore)]
|
||||||
fn task_id_inside_block_on_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn task_id_inside_block_on_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "sync",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "time"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use futures::future::{pending, FutureExt};
|
use futures::future::{pending, FutureExt};
|
||||||
use std::panic;
|
use std::panic;
|
||||||
@@ -433,6 +442,7 @@ mod spawn_local {
|
|||||||
set.spawn_local(async {});
|
set.spawn_local(async {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
#[should_panic(
|
#[should_panic(
|
||||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi doesn't support threads
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "macros")
|
||||||
|
))]
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[cfg_attr(not(target_family = "wasm"), tokio::test(flavor = "multi_thread"))]
|
||||||
|
#[cfg_attr(target_family = "wasm", tokio::test)]
|
||||||
async fn local() {
|
async fn local() {
|
||||||
tokio::task_local! {
|
tokio::task_local! {
|
||||||
static REQ_ID: u32;
|
static REQ_ID: u32;
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))]
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")),
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "macros")
|
||||||
|
))]
|
||||||
#![cfg(panic = "unwind")]
|
#![cfg(panic = "unwind")]
|
||||||
|
|
||||||
use futures::future;
|
use futures::future;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
use tokio::task::{self, block_in_place};
|
use tokio::task;
|
||||||
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
|
use tokio::task::block_in_place;
|
||||||
|
|
||||||
mod support {
|
mod support {
|
||||||
pub mod panic;
|
pub mod panic;
|
||||||
@@ -13,6 +18,7 @@ mod support {
|
|||||||
use support::panic::test_panic;
|
use support::panic::test_panic;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rt-multi-thread")]
|
||||||
fn block_in_place_panic_caller() -> Result<(), Box<dyn Error>> {
|
fn block_in_place_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
let panic_location_file = test_panic(|| {
|
let panic_location_file = test_panic(|| {
|
||||||
let rt = Builder::new_current_thread().enable_all().build().unwrap();
|
let rt = Builder::new_current_thread().enable_all().build().unwrap();
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
#![cfg(all(feature = "full", not(target_os = "wasi"), tokio_unstable))]
|
#![cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "full",
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "macros")
|
||||||
|
),
|
||||||
|
not(target_os = "wasi"),
|
||||||
|
tokio_unstable
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
use tokio_test::task::spawn;
|
use tokio_test::task::spawn;
|
||||||
@@ -15,6 +22,7 @@ fn yield_now_outside_of_runtime() {
|
|||||||
assert!(task.poll().is_ready());
|
assert!(task.poll().is_ready());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn yield_now_external_executor_and_block_in_place() {
|
async fn yield_now_external_executor_and_block_in_place() {
|
||||||
let j = tokio::spawn(async {
|
let j = tokio::spawn(async {
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "test-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::time::{self, Duration, Instant};
|
use tokio::time::{self, Duration, Instant};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "test-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|||||||
+20
-14
@@ -1,5 +1,8 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
|
#![cfg(any(
|
||||||
|
all(feature = "full", not(target_os = "wasi")), // Wasi doesn't support panic recovery
|
||||||
|
all(target_os = "emscripten", feature = "rt", feature = "time")
|
||||||
|
))]
|
||||||
#![cfg(panic = "unwind")]
|
#![cfg(panic = "unwind")]
|
||||||
|
|
||||||
use futures::future;
|
use futures::future;
|
||||||
@@ -22,21 +25,24 @@ fn rt_combinations() -> Vec<Runtime> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
rts.push(rt);
|
rts.push(rt);
|
||||||
|
|
||||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
.worker_threads(1)
|
{
|
||||||
.enable_all()
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
.build()
|
.worker_threads(1)
|
||||||
.unwrap();
|
.enable_all()
|
||||||
rts.push(rt);
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
rts.push(rt);
|
||||||
|
|
||||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
.worker_threads(4)
|
.worker_threads(4)
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
rts.push(rt);
|
rts.push(rt);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(tokio_unstable)]
|
#[cfg(all(tokio_unstable, not(target_os = "emscripten")))]
|
||||||
{
|
{
|
||||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
.worker_threads(1)
|
.worker_threads(1)
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "test-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
#![cfg(not(miri))] // Too slow on miri.
|
#![cfg(not(miri))] // Too slow on miri.
|
||||||
|
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
@@ -7,7 +15,7 @@ use rand::{rngs::StdRng, Rng};
|
|||||||
use tokio::time::{self, Duration, Instant, Sleep};
|
use tokio::time::{self, Duration, Instant, Sleep};
|
||||||
use tokio_test::{assert_elapsed, 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"))]
|
#[cfg(all(feature = "full", not(target_os = "wasi")))]
|
||||||
use tokio_test::assert_err;
|
use tokio_test::assert_err;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "test-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
#![cfg(not(miri))] // Too slow on Miri.
|
#![cfg(not(miri))] // Too slow on Miri.
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(feature = "full")]
|
#![cfg(any(
|
||||||
|
feature = "full",
|
||||||
|
all(
|
||||||
|
target_os = "emscripten",
|
||||||
|
feature = "rt",
|
||||||
|
feature = "macros",
|
||||||
|
feature = "test-util"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tokio::time::{self, timeout, timeout_at, Instant};
|
use tokio::time::{self, timeout, timeout_at, Instant};
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
#![cfg(all(
|
||||||
|
target_arch = "wasm32",
|
||||||
|
not(target_os = "wasi"),
|
||||||
|
not(target_os = "emscripten")
|
||||||
|
))]
|
||||||
|
|
||||||
use wasm_bindgen_test::wasm_bindgen_test;
|
use wasm_bindgen_test::wasm_bindgen_test;
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user