test: add tests for time in wasm32-unknown-unknown (#7510)

This commit is contained in:
unvalley 2025-09-09 19:31:14 +09:00 committed by GitHub
parent 8efd04e382
commit f07233f742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 3 deletions

View File

@ -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:

40
tokio/tests/time_wasm.rs Normal file
View File

@ -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 });
}