Skip to content

Commit

Permalink
Merge pull request #44 from fastly/pch/fix_40
Browse files Browse the repository at this point in the history
Use wasmtime-wasi in async mode
  • Loading branch information
aturon authored Jul 15, 2021
2 parents 8c0253f + fd71284 commit c0dd968
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cli/tests/sleep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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(())
}
2 changes: 1 addition & 1 deletion lib/src/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn make_wasi_ctx(ctx: &ExecuteCtx, session: &Session) -> Result<WasiCtx, anyhow:
}

pub fn link_host_functions(linker: &mut Linker<WasmCtx>) -> 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)?;
Expand Down
3 changes: 3 additions & 0 deletions test-fixtures/src/bin/sleep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
std::thread::sleep(std::time::Duration::from_millis(100))
}

0 comments on commit c0dd968

Please sign in to comment.