Skip to content

Commit 911e5bb

Browse files
committed
tests: ability to trace tests via RUST_LOG
in legacy_client tests only
1 parent 9a0b4a3 commit 911e5bb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ http-body-util = "0.1.0"
4141
tokio = { version = "1", features = ["macros", "test-util", "signal"] }
4242
tokio-test = "0.4"
4343
pretty_env_logger = "0.5"
44+
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
45+
ctor = "0.2"
4446

4547
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dev-dependencies]
4648
pnet_datalink = "0.35.0"

tests/legacy_client.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,25 @@ fn connection_poisoning() {
10681068
// copy/paste-able without relying on external 'use' statements. Detailed inline
10691069
// comments explain the purpose and logic of each section.
10701070

1071-
//XXX: cargo test --features="http1,http2,server,client-legacy" --test legacy_client -- test_connection_error_propagation test_incomplete_message_error --nocapture
1071+
//XXX: can manually run like this:
1072+
// $ RUST_LOG=hyper=trace cargo test --features="http1,http2,server,client-legacy" --test legacy_client -- test_connection_error_propagation test_incomplete_message_error --nocapture
1073+
// $ RUST_LOG=hyper=trace cargo test --all-features --test legacy_client -- --nocapture
1074+
// $ cargo test --all-features --test legacy_client
1075+
// --nocapture is actually not necessary to see the trace messages.
10721076

10731077
use std::error::Error; // needed for .source() eg. error[E0599]: no method named `source` found for struct `hyper_util::client::legacy::Error` in the current scope
10741078

1079+
#[cfg(test)]
1080+
#[ctor::ctor]
1081+
fn init_tracing() {
1082+
// Initialize a tracing subscriber that logs to stderr with TRACE level.
1083+
// Use EnvFilter to respect RUST_LOG directives (e.g., hyper=trace).
1084+
tracing_subscriber::fmt()
1085+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
1086+
.with_writer(std::io::stderr)
1087+
.init();
1088+
}
1089+
10751090
// Helper function to debug byte slices by attempting to interpret them as UTF-8.
10761091
// If the bytes are valid UTF-8, they are printed as a string; otherwise, they are
10771092
// printed as a raw byte array. This aids in debugging tokio_test::io::Mock mismatches.

0 commit comments

Comments
 (0)