Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions tokio/tests/time_wasm.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wasm target runs according to this configuration:

tokio/.github/workflows/ci.yml

Lines 1041 to 1057 in 0922aa2

wasm32-unknown-unknown:
name: test tokio for wasm32-unknown-unknown
needs: basics
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
- name: Install wasm-pack
uses: taiki-e/install-action@wasm-pack
- uses: Swatinem/rust-cache@v2
- name: test tokio
run: wasm-pack test --node -- --features "macros sync"
working-directory: tokio

Here, time is not enabled, so this means that we do not run these tests with time enabled at all! You'll have to modify the ci.yml file to test the time case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thank you for clarifying! Do we also need to add rt feature here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to run multiple combinations here to really test this.

Original file line number Diff line number Diff line change
@@ -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 });
}
Loading