Skip to content

Commit f07233f

Browse files
authored
test: add tests for time in wasm32-unknown-unknown (#7510)
1 parent 8efd04e commit f07233f

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,18 @@ jobs:
10091009
working-directory: tokio
10101010

10111011
wasm32-unknown-unknown:
1012-
name: test tokio for wasm32-unknown-unknown
1012+
name: test tokio for wasm32-unknown-unknown (${{ matrix.name }})
10131013
needs: basics
10141014
runs-on: ubuntu-latest
1015+
strategy:
1016+
matrix:
1017+
include:
1018+
- name: macros sync
1019+
features: "macros sync"
1020+
- name: macros sync rt
1021+
features: "macros sync rt"
1022+
- name: macros sync time rt
1023+
features: "macros sync time rt"
10151024
steps:
10161025
- uses: actions/checkout@v5
10171026
- name: Install Rust 1.88.0
@@ -1022,8 +1031,8 @@ jobs:
10221031
uses: taiki-e/install-action@wasm-pack
10231032

10241033
- uses: Swatinem/rust-cache@v2
1025-
- name: test tokio
1026-
run: wasm-pack test --node -- --features "macros sync"
1034+
- name: test tokio (${{ matrix.name }})
1035+
run: wasm-pack test --node -- --features "${{ matrix.features }}"
10271036
working-directory: tokio
10281037

10291038
wasm32-wasip1:

tokio/tests/time_wasm.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![warn(rust_2018_idioms)]
2+
#![cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
3+
4+
use wasm_bindgen_test::wasm_bindgen_test;
5+
6+
#[wasm_bindgen_test]
7+
#[should_panic]
8+
fn instant_now_panics() {
9+
let _ = tokio::time::Instant::now();
10+
}
11+
12+
#[cfg(all(feature = "rt", not(feature = "time")))]
13+
#[wasm_bindgen_test]
14+
fn runtime_without_time_does_not_panic() {
15+
let rt = tokio::runtime::Builder::new_current_thread()
16+
.build()
17+
.unwrap();
18+
rt.block_on(async {});
19+
}
20+
21+
#[cfg(all(feature = "rt", feature = "time"))]
22+
#[wasm_bindgen_test]
23+
#[should_panic] // should remove this once time is supported
24+
fn runtime_with_time_does_not_panic() {
25+
let rt = tokio::runtime::Builder::new_current_thread()
26+
.build()
27+
.unwrap();
28+
rt.block_on(async {});
29+
}
30+
31+
#[cfg(all(feature = "rt", feature = "time"))]
32+
#[wasm_bindgen_test]
33+
#[should_panic]
34+
fn sleep_panics_on_unknown_unknown() {
35+
let rt = tokio::runtime::Builder::new_current_thread()
36+
.enable_time()
37+
.build()
38+
.unwrap();
39+
rt.block_on(async { tokio::time::sleep(core::time::Duration::from_millis(1)).await });
40+
}

0 commit comments

Comments
 (0)