Skip to content

Commit ffc8735

Browse files
quanweiZhouquanwei.zqw
authored andcommitted
example: add debug info for tests
add debug info for tests Fixes: #255 Signed-off-by: Quanwei Zhou <quanweiZhou@linux.alibaba.com>
1 parent ea66980 commit ffc8735

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/sync-test.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
io::{BufRead, BufReader},
3-
process::Command,
3+
process::{Child, Command},
44
time::Duration,
55
};
66

@@ -22,13 +22,19 @@ fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
2222
});
2323
let output = client.stdout.unwrap();
2424
BufReader::new(output).lines().for_each(|line| {
25-
println!("{}", line.unwrap());
25+
println!("client output: {}", line.unwrap());
2626
});
2727
break;
2828
}
2929

3030
match client.try_wait() {
3131
Ok(Some(status)) => {
32+
println!(
33+
"Client exited with status: {:?} success {}",
34+
&status,
35+
&status.success()
36+
);
37+
wait_with_output("client", client);
3238
client_succeeded = status.success();
3339
break;
3440
}
@@ -45,6 +51,7 @@ fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
4551

4652
// be sure to clean up the server, the client should have run to completion
4753
server.kill()?;
54+
wait_with_output("server", server);
4855
assert!(client_succeeded);
4956
Ok(())
5057
}
@@ -59,3 +66,18 @@ fn run_example(example: &str) -> Command {
5966
.current_dir("example");
6067
cmd
6168
}
69+
70+
fn wait_with_output(name: &str, cmd: Child) {
71+
if let Ok(output) = cmd.wait_with_output() {
72+
println!("==== {name} output begin");
73+
println!("==== stdout:");
74+
output.stdout.lines().for_each(|line| {
75+
println!("{}", line.unwrap());
76+
});
77+
println!("==== stderr:");
78+
output.stderr.lines().for_each(|line| {
79+
println!("{}", line.unwrap());
80+
});
81+
println!("==== {name} output end");
82+
}
83+
}

0 commit comments

Comments
 (0)