Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

harness: consume output of balancer when running tests #1221

Merged
merged 4 commits into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions crates/harness/src/test_runner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::{collections::HashMap, net::SocketAddr, sync::Arc};
use std::{collections::HashMap, net::SocketAddr, process::Stdio, sync::Arc};

use tokio::process::{Child, Command};
use tokio::{
io::{AsyncBufReadExt, BufReader},
process::{Child, Command},
};

use test_context::AsyncTestContext;
use tracing::warn;
Expand Down Expand Up @@ -82,10 +85,12 @@ impl TestRunner {
"debug",
])
.envs(envs)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to start balancer");
println!("waiting for balancer to start");
loop {
println!("waiting for balancer to start");
match client
.get(&format!("http://localhost:{}/api/status", opts.port))
.send()
Expand All @@ -109,6 +114,36 @@ impl TestRunner {
}
}

let child_stdout = BufReader::new(child.stdout.take().expect("failed to get child stdout"));
let child_stderr = BufReader::new(child.stderr.take().expect("failed to get child stderr"));

async fn relog_lines(
mut reader: BufReader<impl tokio::io::AsyncRead + Unpin>,
prefix: &str,
) {
let mut line = String::new();
loop {
line.clear();
match reader.read_line(&mut line).await {
Ok(0) => break,
Ok(_) => {
println!("{}: {}", prefix, line);
}
Err(e) => {
println!("{} error: {}", prefix, e);
break;
}
}
}
}

tokio::spawn(async move {
relog_lines(child_stdout, "balancer stdout").await;
});
tokio::spawn(async move {
relog_lines(child_stderr, "balancer stderr").await;
});

Ok(child)
}

Expand Down
Loading