diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7d2c1301ed..20175e198f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1009,9 +1009,18 @@ jobs: working-directory: tokio wasm32-unknown-unknown: - name: test tokio for wasm32-unknown-unknown + name: test tokio for wasm32-unknown-unknown (${{ matrix.name }}) needs: basics runs-on: ubuntu-latest + strategy: + matrix: + include: + - name: macros sync + features: "macros sync" + - name: macros sync rt + features: "macros sync rt" + - name: macros sync time rt + features: "macros sync time rt" steps: - uses: actions/checkout@v5 - name: Install Rust 1.88.0 @@ -1022,8 +1031,8 @@ jobs: uses: taiki-e/install-action@wasm-pack - uses: Swatinem/rust-cache@v2 - - name: test tokio - run: wasm-pack test --node -- --features "macros sync" + - name: test tokio (${{ matrix.name }}) + run: wasm-pack test --node -- --features "${{ matrix.features }}" working-directory: tokio wasm32-wasip1: diff --git a/tokio/tests/time_wasm.rs b/tokio/tests/time_wasm.rs new file mode 100644 index 00000000000..8e0483f2041 --- /dev/null +++ b/tokio/tests/time_wasm.rs @@ -0,0 +1,40 @@ +#![warn(rust_2018_idioms)] +#![cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] + +use wasm_bindgen_test::wasm_bindgen_test; + +#[wasm_bindgen_test] +#[should_panic] +fn instant_now_panics() { + let _ = tokio::time::Instant::now(); +} + +#[cfg(all(feature = "rt", not(feature = "time")))] +#[wasm_bindgen_test] +fn runtime_without_time_does_not_panic() { + let rt = tokio::runtime::Builder::new_current_thread() + .build() + .unwrap(); + rt.block_on(async {}); +} + +#[cfg(all(feature = "rt", feature = "time"))] +#[wasm_bindgen_test] +#[should_panic] // should remove this once time is supported +fn runtime_with_time_does_not_panic() { + let rt = tokio::runtime::Builder::new_current_thread() + .build() + .unwrap(); + rt.block_on(async {}); +} + +#[cfg(all(feature = "rt", feature = "time"))] +#[wasm_bindgen_test] +#[should_panic] +fn sleep_panics_on_unknown_unknown() { + let rt = tokio::runtime::Builder::new_current_thread() + .enable_time() + .build() + .unwrap(); + rt.block_on(async { tokio::time::sleep(core::time::Duration::from_millis(1)).await }); +}