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

chore(test): improve the start method of test_server #1583

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions integration/src/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, Write};
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
use std::path::{Path, PathBuf};
use std::process::{Child, Command};
use std::process::{Child, Command, Stdio};
use std::thread::{panicking, sleep};
use std::time::Duration;

Expand Down Expand Up @@ -158,11 +158,11 @@ impl TestServer {
self.cleanup();
let files_path = self.local_data_path.clone();
let mut command = if let Some(server_executable_path) = &self.server_executable_path {
std::process::Command::new(server_executable_path)
Command::new(server_executable_path)
} else {
Command::cargo_bin("iggy-server").unwrap()
};
command.env(SYSTEM_PATH_ENV_VAR, files_path.clone());
command.env(SYSTEM_PATH_ENV_VAR, files_path);
command.envs(self.envs.clone());

// By default, server all logs are redirected to files,
Expand All @@ -171,8 +171,8 @@ impl TestServer {
if std::env::var(TEST_VERBOSITY_ENV_VAR).is_ok()
|| self.envs.contains_key(TEST_VERBOSITY_ENV_VAR)
{
command.stdout(std::process::Stdio::inherit());
command.stderr(std::process::Stdio::inherit());
command.stdout(Stdio::inherit());
command.stderr(Stdio::inherit());
} else {
command.stdout(self.get_stdout_file());
self.stdout_file_path = Some(fs::canonicalize(self.get_stdout_file_path()).unwrap());
Expand All @@ -192,6 +192,15 @@ impl TestServer {
}
});
}
if self.child_handle.as_ref().unwrap().stderr.is_some() {
let child_stderr = self.child_handle.as_mut().unwrap().stderr.take().unwrap();
std::thread::spawn(move || {
let reader = BufReader::new(child_stderr);
for line in reader.lines() {
eprintln!("{}", line.unwrap());
}
});
}
self.wait_until_server_has_bound();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please improve it by checking if test server is alive in the method wait_until_server_has_bound()?

}

Expand Down