Skip to content

Commit 8656e20

Browse files
authored
Start running some async tests in CI (#1286)
This commit starts to execute some async tests in CI via artifacts downloaded from the wasip3-prototyping repository. While the status is reported on PRs this won't actually result in failing to merge something if the job fails at this time since it's known that async is a bit of a shifting landscape. In the meantime it's hoped that at least having this status on PRs will be sufficient for seeing failures for now. The actual set of initial tests here are relatively edge-case-y where I added them some time ago when testing Rust bindings. They're not comprehensive by any means but are hopefully at least a start. I hope to next start adding more tests in follow-up PRs.
1 parent 3395dd6 commit 8656e20

File tree

20 files changed

+300
-0
lines changed

20 files changed

+300
-0
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,33 @@ jobs:
111111
--artifacts target/artifacts \
112112
--rust-wit-bindgen-path ./crates/guest-rust
113113
114+
# While we're working on getting wasip3-prototyping upstream in wasmtime
115+
# itself run tests here in separate async job. Note that this job is NOT
116+
# required for merging but it reports its status anyway to alert folks to at
117+
# least the "big red X" status. The goal here is that this is known to be a
118+
# bit unstable as the async foundations are shifting over time but this at
119+
# least enables testing async things in this repository more easily.
120+
async:
121+
name: Test Async
122+
runs-on: ubuntu-latest
123+
steps:
124+
- uses: actions/checkout@v4
125+
with:
126+
submodules: true
127+
- name: Install Rust
128+
run: rustup update stable --no-self-update && rustup default stable
129+
- run: rustup target add wasm32-wasip1
130+
- uses: ./.github/actions/install-wasi-sdk
131+
- run: |
132+
curl -L https://github.com/bytecodealliance/wasip3-prototyping/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz | tar xJvf -
133+
echo "WASMTIME=`pwd`/wasmtime-dev-x86_64-linux/wasmtime" >> $GITHUB_ENV
134+
- run: |
135+
cargo run test --languages rust tests/runtime-async \
136+
--artifacts target/artifacts \
137+
--rust-wit-bindgen-path ./crates/guest-rust \
138+
--rust-target wasm32-wasip1 \
139+
--runner "$WASMTIME -W component-model-async"
140+
114141
test_unit:
115142
name: Crate Unit Tests
116143
runs-on: ubuntu-latest
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ args = '--async=-all'
2+
3+
include!(env!("BINDINGS"));
4+
5+
use crate::a::b::the_test::f;
6+
7+
fn main() {
8+
let (tx, rx) = wit_future::new();
9+
10+
drop(tx.write(()));
11+
12+
f(rx);
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include!(env!("BINDINGS"));
2+
3+
struct Component;
4+
5+
export!(Component);
6+
7+
use crate::exports::a::b::the_test::Guest;
8+
9+
use wit_bindgen::rt::async_support::FutureReader;
10+
11+
impl Guest for Component {
12+
async fn f(future: FutureReader<()>) {
13+
assert!(future.await.is_none());
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package a:b;
2+
3+
interface the-test {
4+
f: async func(param: future);
5+
}
6+
7+
world test {
8+
export the-test;
9+
}
10+
world runner {
11+
import the-test;
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include!(env!("BINDINGS"));
2+
3+
use crate::a::b::the_test::f;
4+
5+
fn main() {
6+
let (tx, rx) = wit_future::new();
7+
8+
let rx = f(rx);
9+
drop(tx);
10+
drop(rx);
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include!(env!("BINDINGS"));
2+
3+
struct Component;
4+
5+
export!(Component);
6+
7+
use crate::exports::a::b::the_test::Guest;
8+
9+
use wit_bindgen::rt::async_support::FutureReader;
10+
11+
impl Guest for Component {
12+
fn f(future: FutureReader<()>) -> FutureReader<()> {
13+
future
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package a:b;
2+
3+
interface the-test {
4+
f: func(param: future) -> future;
5+
}
6+
7+
world test {
8+
export the-test;
9+
}
10+
world runner {
11+
import the-test;
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include!(env!("BINDINGS"));
2+
3+
use crate::a::b::the_test::{get, set};
4+
5+
fn main() {
6+
let (tx, rx) = wit_future::new();
7+
8+
set(rx);
9+
let rx = get();
10+
drop(tx);
11+
drop(rx);
12+
13+
wit_future::new::<()>();
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include!(env!("BINDINGS"));
2+
3+
use crate::exports::a::b::the_test::Guest;
4+
use std::cell::Cell;
5+
use wit_bindgen::rt::async_support::FutureReader;
6+
7+
struct Component;
8+
9+
export!(Component);
10+
11+
std::thread_local!(
12+
static SLOT: Cell<Option<FutureReader<()>>> = const { Cell::new(None) };
13+
);
14+
15+
impl Guest for Component {
16+
fn set(future: FutureReader<()>) {
17+
SLOT.with(|s| s.set(Some(future)));
18+
}
19+
fn get() -> FutureReader<()> {
20+
SLOT.with(|s| s.replace(None).unwrap())
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package a:b;
2+
3+
interface the-test {
4+
set: func(param: future);
5+
get: func() -> future;
6+
}
7+
8+
world test {
9+
export the-test;
10+
}
11+
world runner {
12+
import the-test;
13+
}

0 commit comments

Comments
 (0)