Skip to content

Commit

Permalink
tests: add all examples to test
Browse files Browse the repository at this point in the history
Add async-example and async-stream-example to test.

Signed-off-by: Tim Zhang <[email protected]>
  • Loading branch information
Tim-Zhang committed Feb 6, 2025
1 parent cd0f597 commit 423a4d2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/sync-test.rs → tests/run-examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use std::{
time::Duration,
};

#[test]
fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
fn run_example(server: &str, client: &str) -> Result<(), Box<dyn std::error::Error>> {
// start the server and give it a moment to start.
let mut server = run_example("server").spawn().unwrap();
let mut server = do_run_example(server).spawn().unwrap();
std::thread::sleep(Duration::from_secs(2));

let mut client = run_example("client").spawn().unwrap();
let mut client = do_run_example(client).spawn().unwrap();
let mut client_succeeded = false;
let start = std::time::Instant::now();
let timeout = Duration::from_secs(600);
Expand Down Expand Up @@ -56,7 +55,7 @@ fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn run_example(example: &str) -> Command {
fn do_run_example(example: &str) -> Command {
let mut cmd = Command::new("cargo");
cmd.arg("run")
.arg("--example")
Expand All @@ -81,3 +80,12 @@ fn wait_with_output(name: &str, cmd: Child) {
println!("==== {name} output end");
}
}

#[test]
fn run_examples() -> Result<(), Box<dyn std::error::Error>> {
run_example("server", "client")?;
#[cfg(unix)]
run_example("async-server", "async-client")?;
#[cfg(unix)]
run_example("async-stream-server", "async-stream-client")
}

0 comments on commit 423a4d2

Please sign in to comment.