Isolate smol::Command hang as a test, does not hang

Isaac Clayton created

Change summary

crates/plugin_runtime/Cargo.toml |  3 ++-
crates/plugin_runtime/src/lib.rs | 25 +++++++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)

Detailed changes

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"
+pollster = "0.2.5"
+smol = "1.2.5"

crates/plugin_runtime/src/lib.rs 🔗

@@ -19,6 +19,7 @@ mod tests {
             and_back: WasiFn<u32, u32>,
             imports: WasiFn<u32, u32>,
             half_async: WasiFn<u32, u32>,
+            echo_async: WasiFn<String, String>,
         }
 
         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());
         }