fix: do not print test output to logs except on failure (#1840)
* fix: do not print test output to logs except on failure * docs: update CONTRIBUTING.mdpull/24376/head
parent
403f7297e1
commit
89757d7232
|
@ -120,15 +120,15 @@ RUST_LOG=debug,hyper::proto::h1=info,h2=info cargo test --workspace
|
|||
|
||||
### End-to-End Tests
|
||||
|
||||
There are end-to-end tests that spin up a server and make requests via the client library and API. They can be found in `tests/end_to_end_cases`
|
||||
There are end-to-end tests that spin up a server and make requests via the client library and API. They can be found in `tests/end_to_end_cases`
|
||||
|
||||
They are run by `cargo test --workspace` command but can be run exclusively with:
|
||||
|
||||
```
|
||||
cargo test --test end-to-end
|
||||
```
|
||||
```
|
||||
|
||||
Each server writes its logs to a temporary file and this is printed to stdout on shutdown, bypassing the default test log capturing.
|
||||
Each server writes its logs to a temporary file and this is captured when the server shutsdown.
|
||||
|
||||
If you are debugging a failing end-to-end test, you will likely want to run with `--nocapture` to also get the logs from the test execution in addition to the server:
|
||||
|
||||
|
@ -139,7 +139,7 @@ cargo test --test end-to-end -- my_failing_test --nocapture
|
|||
If running multiple tests in parallel:
|
||||
|
||||
* The output may be interleaved
|
||||
* Multiple tests may share the same server instance
|
||||
* Multiple tests may share the same server instance and thus the server logs may be captured in the output of a different test than the one that is failing.
|
||||
|
||||
When debugging a failing test it is therefore recommended you run a single test, or disable parallel test execution
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ impl std::fmt::Display for TestServer {
|
|||
|
||||
impl Drop for TestServer {
|
||||
fn drop(&mut self) {
|
||||
use std::io::{Read, Write};
|
||||
use std::io::Read;
|
||||
|
||||
let mut server_lock = self
|
||||
.server_process
|
||||
|
@ -521,23 +521,29 @@ impl Drop for TestServer {
|
|||
.wait()
|
||||
.expect("Should have been able to wait for shutdown");
|
||||
|
||||
let mut out = std::io::stdout();
|
||||
let mut f = std::fs::File::open(&server_lock.log_path).expect("failed to open log file");
|
||||
let mut buffer = [0_u8; 8 * 1024];
|
||||
|
||||
writeln!(out, "****************").unwrap();
|
||||
writeln!(out, "Start TestServer Output").unwrap();
|
||||
writeln!(out, "****************").unwrap();
|
||||
println!("****************");
|
||||
println!("Start TestServer Output");
|
||||
println!("****************");
|
||||
|
||||
while let Ok(read) = f.read(&mut buffer) {
|
||||
if read == 0 {
|
||||
break;
|
||||
}
|
||||
out.write_all(&buffer[..read]).unwrap();
|
||||
if let Ok(str) = std::str::from_utf8(&buffer[..read]) {
|
||||
print!("{}", str);
|
||||
} else {
|
||||
println!(
|
||||
"\n\n-- ERROR IN TRANSFER -- please see {:?} for raw contents ---\n\n",
|
||||
&server_lock.log_path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(out, "****************").unwrap();
|
||||
writeln!(out, "End TestServer Output").unwrap();
|
||||
writeln!(out, "****************").unwrap();
|
||||
println!("****************");
|
||||
println!("End TestServer Output");
|
||||
println!("****************");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue