From 46d1b7b35bf9f69bcd9d27f3263b0bd3f130aa16 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 15 Jul 2021 11:27:21 -0700 Subject: [PATCH 1/3] wasmtime_wasi: link with the async (tokio) version of hostcalls closes #40 --- lib/src/linking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/linking.rs b/lib/src/linking.rs index 195d4786..8eedcbcc 100644 --- a/lib/src/linking.rs +++ b/lib/src/linking.rs @@ -79,7 +79,7 @@ fn make_wasi_ctx(ctx: &ExecuteCtx, session: &Session) -> Result) -> Result<(), Error> { - wasmtime_wasi::add_to_linker(linker, WasmCtx::wasi)?; + wasmtime_wasi::tokio::add_to_linker(linker, WasmCtx::wasi)?; wiggle_abi::fastly_abi::add_to_linker(linker, WasmCtx::session)?; wiggle_abi::fastly_dictionary::add_to_linker(linker, WasmCtx::session)?; wiggle_abi::fastly_geo::add_to_linker(linker, WasmCtx::session)?; From 20bfd1d70fa8f1a8912495d51cfc54675cd101dc Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 15 Jul 2021 11:35:44 -0700 Subject: [PATCH 2/3] add test fixture which exercises wasi sleep without prior commit, this would crash because wasi is trying to run in a dummy executor: [pat@finknottle:viceroy/cli]% cargo test --test sleep Compiling viceroy-lib v0.2.2 (/home/pat/src/viceroy/lib) Compiling viceroy-cli v0.2.2 (/home/pat/src/viceroy/cli) Finished test [unoptimized + debuginfo] target(s) in 16.23s Running tests/sleep.rs (/home/pat/src/viceroy/target/debug/deps/sleep-f21a87ee4efbda79) running 1 test test empty_ok_response_by_default_after_sleep ... FAILED failures: ---- empty_ok_response_by_default_after_sleep stdout ---- thread 'tokio-runtime-worker' panicked at 'Cannot wait on pending future: must enable wiggle "async" future and execute on an async Store', /home/pat/.cargo/registry/src/github.com-1ecc6299db9ec823/wiggle-0.28.0/src/lib.rs:946:13 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'empty_ok_response_by_default_after_sleep' panicked at 'guest worker finished without panicking: JoinError::Panic(...)', lib/src/execute.rs:189:18 failures: empty_ok_response_by_default_after_sleep test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.49s --- cli/tests/sleep.rs | 22 ++++++++++++++++++++++ test-fixtures/src/bin/sleep.rs | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 cli/tests/sleep.rs create mode 100644 test-fixtures/src/bin/sleep.rs diff --git a/cli/tests/sleep.rs b/cli/tests/sleep.rs new file mode 100644 index 00000000..18d1133d --- /dev/null +++ b/cli/tests/sleep.rs @@ -0,0 +1,22 @@ +mod common; +use common::{Test, TestResult}; +use hyper::{body::to_bytes, StatusCode}; +/// Run a program that only sleeps. This exercises async functionality in wasi. +/// Check that an empty response is sent downstream by default. +/// +/// `sleep.wasm` is a guest program which sleeps for 100 milliseconds,then returns. +#[tokio::test(flavor = "multi_thread")] +async fn empty_ok_response_by_default_after_sleep() -> TestResult { + let resp = Test::using_fixture("sleep.wasm").against_empty().await; + + assert_eq!(resp.status(), StatusCode::OK); + assert!(to_bytes(resp.into_body()) + .await + .expect("can read body") + .to_vec() + .is_empty()); + + Ok(()) +} + + diff --git a/test-fixtures/src/bin/sleep.rs b/test-fixtures/src/bin/sleep.rs new file mode 100644 index 00000000..abb503bc --- /dev/null +++ b/test-fixtures/src/bin/sleep.rs @@ -0,0 +1,3 @@ +fn main() { + std::thread::sleep(std::time::Duration::from_millis(100)) +} From fd712846c4517228f9f717074fa7ac6aae9fee01 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 15 Jul 2021 11:59:12 -0700 Subject: [PATCH 3/3] cargo fmt!! how could you betray me nvim --- cli/tests/sleep.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/tests/sleep.rs b/cli/tests/sleep.rs index 18d1133d..dec602ea 100644 --- a/cli/tests/sleep.rs +++ b/cli/tests/sleep.rs @@ -18,5 +18,3 @@ async fn empty_ok_response_by_default_after_sleep() -> TestResult { Ok(()) } - -