| 5 | use wasmtime::Result; |
| 6 | |
| 7 | pub fn run_wasmtime_piped(component_path: &str) -> Result<()> { |
| 8 | let mut producer = get_wasmtime_command()? |
| 9 | .arg("run") |
| 10 | .arg("-Wcomponent-model") |
| 11 | .arg("--env") |
| 12 | .arg("PIPED_SIDE=PRODUCER") |
| 13 | .arg(component_path) |
| 14 | .stdout(Stdio::piped()) |
| 15 | .spawn()?; |
| 16 | |
| 17 | let mut consumer = get_wasmtime_command()? |
| 18 | .arg("run") |
| 19 | .arg("-Wcomponent-model") |
| 20 | .arg("--env") |
| 21 | .arg("PIPED_SIDE=CONSUMER") |
| 22 | .arg(component_path) |
| 23 | .stdin(producer.stdout.take().unwrap()) |
| 24 | .spawn()?; |
| 25 | |
| 26 | let producer = producer.wait()?; |
| 27 | if !producer.success() { |
| 28 | // make sure the consumer gets killed off |
| 29 | if consumer.try_wait().is_err() { |
| 30 | consumer.kill().expect("Failed to kill consumer"); |
| 31 | } |
| 32 | |
| 33 | panic!("Producer failed"); |
| 34 | } |
| 35 | |
| 36 | assert!(consumer.wait()?.success(), "Consumer failed"); |
| 37 | |
| 38 | Ok(()) |
| 39 | } |
| 40 | |
| 41 | mod test_programs { |
| 42 | use super::run_wasmtime_piped; |