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

small integration test improvements. #194

Merged
merged 4 commits into from
Mar 8, 2023
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
37 changes: 29 additions & 8 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::net::TcpStream;
use std::path::PathBuf;
use std::process::Command;
use std::thread;
Expand All @@ -21,6 +22,16 @@ fn client_command() -> Command {
Command::new(examples_dir().join("client"))
}

fn wait_for_server(addr: &str) {
for i in 0..10 {
if let Ok(_) = TcpStream::connect(addr) {
return;
}
thread::sleep(time::Duration::from_millis(i * 100));
}
panic!("failed to connect to {:?} after 10 tries", addr);
}

#[test]
fn client() {
let rc = client_command()
Expand All @@ -38,20 +49,29 @@ fn server() {
.spawn()
.expect("cannot run server example");

thread::sleep(time::Duration::from_secs(1));
let addr = "localhost:1337";
wait_for_server(addr);

let output = Command::new("curl")
.arg("--insecure")
.arg("--http1.0")
.arg("--silent")
.arg("https://localhost:1337")
.arg(format!("https://{}", addr))
.output()
.expect("cannot run curl");

println!("client output: {:?}", output.stdout);
assert_eq!(output.stdout, b"Try POST /echo\n");

srv.kill().unwrap();

if !output.status.success() {
let version_stdout = Command::new("curl")
.arg("--version")
.output()
.expect("cannot run curl to collect --version")
.stdout;
println!("curl version: {}", String::from_utf8_lossy(&version_stdout));
println!("curl stderr:\n{}", String::from_utf8_lossy(&output.stderr));
}

assert_eq!(String::from_utf8_lossy(&*output.stdout), "Try POST /echo\n");
}

#[test]
Expand All @@ -61,10 +81,11 @@ fn custom_ca_store() {
.spawn()
.expect("cannot run server example");

thread::sleep(time::Duration::from_secs(1));
let addr = "localhost:1338";
wait_for_server(addr);

let rc = client_command()
.arg("https://localhost:1338")
.arg(format!("https://{}", addr))
.arg("examples/sample.pem")
.output()
.expect("cannot run client example");
Expand Down