From 92c4552146535877850862de21c6e3e7e6781466 Mon Sep 17 00:00:00 2001 From: Isaac Clayton Date: Fri, 1 Jul 2022 11:25:40 +0200 Subject: [PATCH] Isolate smol::Command hang as a test, does not hang --- crates/plugin_runtime/Cargo.toml | 3 ++- crates/plugin_runtime/src/lib.rs | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/plugin_runtime/Cargo.toml b/crates/plugin_runtime/Cargo.toml index 492b7e14c9..a145b12a19 100644 --- a/crates/plugin_runtime/Cargo.toml +++ b/crates/plugin_runtime/Cargo.toml @@ -11,4 +11,5 @@ anyhow = { version = "1.0", features = ["std"] } serde = "1.0" serde_json = "1.0" bincode = "1.3" -pollster = "0.2.5" \ No newline at end of file +pollster = "0.2.5" +smol = "1.2.5" diff --git a/crates/plugin_runtime/src/lib.rs b/crates/plugin_runtime/src/lib.rs index 92a75ddb3c..12b1c3b4f4 100644 --- a/crates/plugin_runtime/src/lib.rs +++ b/crates/plugin_runtime/src/lib.rs @@ -19,6 +19,7 @@ mod tests { and_back: WasiFn, imports: WasiFn, half_async: WasiFn, + echo_async: WasiFn, } async { @@ -34,6 +35,22 @@ mod tests { .unwrap() .host_function_async("import_half", |a: u32| async move { a / 2 }) .unwrap() + .host_function_async("command_async", |command: String| async move { + // TODO: actual thing + dbg!(&command); + let mut args = command.split(' '); + let command = args.next().unwrap(); + smol::process::Command::new(command) + .args(args) + .output() + .await + .ok() + .map(|output| { + dbg!("Did run command!"); + output.stdout + }) + }) + .unwrap() .init(include_bytes!("../../../plugins/bin/test_plugin.wasm")) .await .unwrap(); @@ -49,6 +66,7 @@ mod tests { and_back: runtime.function("and_back").unwrap(), imports: runtime.function("imports").unwrap(), half_async: runtime.function("half_async").unwrap(), + echo_async: runtime.function("echo_async").unwrap(), }; let unsorted = vec![1, 3, 4, 2, 5]; @@ -64,6 +82,13 @@ mod tests { assert_eq!(runtime.call(&plugin.and_back, 1).await.unwrap(), 8); assert_eq!(runtime.call(&plugin.imports, 1).await.unwrap(), 8); assert_eq!(runtime.call(&plugin.half_async, 4).await.unwrap(), 2); + assert_eq!( + runtime + .call(&plugin.echo_async, "eko".into()) + .await + .unwrap(), + "eko\n" + ); // dbg!("{}", runtime.call(&plugin.and_back, 1).await.unwrap()); }