Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
hatoo committed Feb 13, 2025
1 parent 069aaa8 commit a8050d7
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,33 +861,34 @@ async fn test_proxy_with_setting(https: bool, http2: bool, proxy_http2: bool) {

tokio::spawn(proxy_serve);

let cargo_bin = Command::cargo_bin("oha").unwrap();
let mut proc = std::process::Command::new(cargo_bin.get_program());
std::mem::drop(cargo_bin);

let scheme = if https { "https" } else { "http" };
proc.args(["--no-tui", "--debug", "--insecure", "-x"])
.arg(format!("http://127.0.0.1:{proxy_port}/"))
.args(["--proxy-header", "proxy-authorization: test"])
.arg(format!("{scheme}://example.com/"));
if http2 {
proc.arg("--http2");
}
if proxy_http2 {
proc.arg("--proxy-http2");
}
let (tx, rx) = flume::bounded(1);

std::thread::spawn(move || {
let mut command = std::process::Command::new("cargo");
command.args(["run", "--"]);

let scheme = if https { "https" } else { "http" };
command
.args(["--no-tui", "--debug", "--insecure", "-x"])
.arg(format!("http://127.0.0.1:{proxy_port}/"))
.args(["--proxy-header", "proxy-authorization: test"])
.arg(format!("{scheme}://example.com/"));
if http2 {
command.arg("--http2");
}
if proxy_http2 {
command.arg("--proxy-http2");
}

// When std::process::Stdio::piped() is used, the wait_with_output() method will hang in Windows.
proc.stdin(std::process::Stdio::inherit())
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit());
let mut child = proc.spawn().unwrap();
assert!(
tokio::task::spawn_blocking(move || { child.wait().unwrap() })
.await
.unwrap()
.success()
);
command.stdin(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
command.stderr(std::process::Stdio::null());

let mut child = command.spawn().unwrap();
tx.send(child.wait().unwrap()).unwrap();
});

assert!(rx.recv_async().await.unwrap().success());
}

#[tokio::test]
Expand Down

0 comments on commit a8050d7

Please sign in to comment.