diff --git a/crates/openwire/tests/events.rs b/crates/openwire/tests/events.rs index b70c6e5..9a9bf10 100644 --- a/crates/openwire/tests/events.rs +++ b/crates/openwire/tests/events.rs @@ -6,12 +6,11 @@ mod support; use std::sync::{Arc, Mutex}; use std::time::Duration; -use http::{Method, Request, Response, StatusCode}; +use http::{Method, Request, StatusCode}; use hyper::body::Incoming; use openwire::{Client, RequestBody, WireErrorKind}; use openwire_test::{ ok_text, spawn_http1, MockResponse, MockWebServer, RecordingEventListenerFactory, - StaticDnsResolver, }; use support::*; @@ -206,83 +205,6 @@ async fn not_modified_is_not_a_redirect() { ); } -#[tokio::test] -async fn tracing_attempt_spans_record_stable_connection_reuse_fields() { - let _trace_test_guard = trace_test_lock().lock().await; - let server = spawn_http1(|_request| async move { ok_text("pooled") }).await; - let trace = TraceCapture::default(); - let client = Client::builder().build().expect("client"); - - with_trace_capture(&trace, async { - let response = client - .execute(empty_request(server.http_url("/first"))) - .await - .expect("response"); - let _ = response.into_body().text().await.expect("body"); - - let response = client - .execute(empty_request(server.http_url("/second"))) - .await - .expect("response"); - let _ = response.into_body().text().await.expect("body"); - }) - .await; - - let spans = trace.spans_named("openwire.attempt"); - assert_eq!(spans.len(), 2, "spans = {spans:?}"); - assert_eq!( - spans[0].fields.get("attempt").map(String::as_str), - Some("1") - ); - assert_eq!( - spans[0].fields.get("retry_count").map(String::as_str), - Some("0") - ); - assert_eq!( - spans[0].fields.get("redirect_count").map(String::as_str), - Some("0") - ); - assert_eq!( - spans[0].fields.get("auth_count").map(String::as_str), - Some("0") - ); - assert_eq!( - spans[0].fields.get("pool_hit").map(String::as_str), - Some("false") - ); - assert!(!spans[0].fields.contains_key("pool_connection_id")); - assert_eq!( - spans[0].fields.get("connection_reused").map(String::as_str), - Some("false") - ); - assert_eq!( - spans[1].fields.get("attempt").map(String::as_str), - Some("1") - ); - assert_eq!( - spans[1].fields.get("auth_count").map(String::as_str), - Some("0") - ); - assert_eq!( - spans[1].fields.get("pool_hit").map(String::as_str), - Some("true") - ); - assert_eq!( - spans[1].fields.get("pool_connection_id"), - spans[1].fields.get("connection_id"), - "spans = {spans:?}", - ); - assert_eq!( - spans[1].fields.get("connection_reused").map(String::as_str), - Some("true") - ); - assert_eq!( - spans[0].fields.get("connection_id"), - spans[1].fields.get("connection_id"), - "spans = {spans:?}", - ); -} - #[tokio::test] async fn interceptors_wrap_transport_in_expected_order() { let server = spawn_http1(|_request| async move { ok_text("ok") }).await; @@ -395,144 +317,3 @@ async fn request_send_events_surround_transport_handoff() { ], ); } - -#[tokio::test] -async fn retry_and_redirect_events_follow_stable_order_and_trace_fields() { - let _trace_test_guard = trace_test_lock().lock().await; - let server = spawn_http1(|request: Request| async move { - match request.uri().path() { - "/redirect-after-retry" => Response::builder() - .status(StatusCode::FOUND) - .header("location", "/redirect-target") - .body(http_body_util::Full::new(bytes::Bytes::new())) - .expect("redirect response"), - _ => ok_text("redirect after retry"), - } - }) - .await; - - let connector = FailingTcpConnector::new(1); - let events = RecordingEventListenerFactory::default(); - let trace = TraceCapture::default(); - - let client = Client::builder() - .dns_resolver(StaticDnsResolver::new(server.addr())) - .tcp_connector(connector) - .event_listener_factory(events.clone()) - .max_retries(1) - .build() - .expect("client"); - - with_trace_capture(&trace, async { - let response = client - .execute(empty_request(format!( - "http://openwire.test:{}/redirect-after-retry", - server.addr().port() - ))) - .await - .expect("response"); - let _ = response.into_body().text().await.expect("body"); - }) - .await; - - let events = events.events(); - assert_event_subsequence( - &events, - &[ - "call_start GET", - "connect_failed ", - "retry 1 connect", - "connect_end ", - "connection_acquired ", - "response_headers_end 302 Found", - // Intermediate redirect body is drained so the connection can be - // reused before the follow-up hop starts. - "response_body_end ", - "connection_released ", - "redirect 1 http://openwire.test:", - "connection_acquired ", - "response_headers_end 200 OK", - "response_body_end 20", - "connection_released ", - "call_end", - ], - ); - - let retry_event = trace - .event_by_message("retrying request after connection-establishment failure") - .or_else(|| trace.event_with_field("retry_reason", "connect")) - .unwrap_or_else(|| { - panic!( - "retry trace event missing; captured messages = {:?}", - trace.event_messages() - ) - }); - assert_eq!( - retry_event.fields.get("attempt").map(String::as_str), - Some("2") - ); - assert_eq!( - retry_event.fields.get("retry_count").map(String::as_str), - Some("1") - ); - assert_eq!( - retry_event.fields.get("redirect_count").map(String::as_str), - Some("0") - ); - assert_eq!( - retry_event.fields.get("auth_count").map(String::as_str), - Some("0") - ); - assert_eq!( - retry_event - .fields - .get("retry_reason") - .map(|value| normalize_trace_message(value)), - Some("connect".to_owned()) - ); - - let redirect_event = trace - .event_by_message("following redirect") - .or_else(|| { - trace - .inner - .lock() - .expect("trace capture lock") - .events - .iter() - .find(|event| event.fields.contains_key("redirect_location")) - .cloned() - }) - .unwrap_or_else(|| { - panic!( - "redirect trace event missing; captured messages = {:?}", - trace.event_messages() - ) - }); - assert_eq!( - redirect_event.fields.get("attempt").map(String::as_str), - Some("3") - ); - assert_eq!( - redirect_event.fields.get("retry_count").map(String::as_str), - Some("1") - ); - assert_eq!( - redirect_event - .fields - .get("redirect_count") - .map(String::as_str), - Some("1") - ); - assert_eq!( - redirect_event.fields.get("auth_count").map(String::as_str), - Some("0") - ); - assert!( - redirect_event - .fields - .get("redirect_location") - .is_some_and(|location| location.contains("/redirect-target")), - "redirect event = {redirect_event:?}", - ); -} diff --git a/crates/openwire/tests/support/harness.rs b/crates/openwire/tests/support/harness.rs index 201492a..9897b86 100644 --- a/crates/openwire/tests/support/harness.rs +++ b/crates/openwire/tests/support/harness.rs @@ -2424,11 +2424,6 @@ where .await } -pub fn trace_test_lock() -> &'static AsyncMutex<()> { - static LOCK: OnceLock> = OnceLock::new(); - LOCK.get_or_init(|| AsyncMutex::new(())) -} - impl Layer for TraceCapture where S: Subscriber + for<'span> LookupSpan<'span>, diff --git a/crates/openwire/tests/timeout_cancel.rs b/crates/openwire/tests/timeout_cancel.rs index 4adf78f..3774374 100644 --- a/crates/openwire/tests/timeout_cancel.rs +++ b/crates/openwire/tests/timeout_cancel.rs @@ -551,80 +551,6 @@ async fn dropping_response_body_without_consuming_it_ends_the_body_and_call() { ); } -#[tokio::test] -async fn response_body_failures_emit_call_failed_but_not_response_body_end() { - let _trace_test_guard = trace_test_lock().lock().await; - let server = spawn_raw_http1_response( - b"HTTP/1.1 200 OK\r\nContent-Length: 5\r\nConnection: close\r\n\r\nabc".to_vec(), - ) - .await; - let events = RecordingEventListenerFactory::default(); - let trace = TraceCapture::default(); - - let client = Client::builder() - .dns_resolver(StaticDnsResolver::new(server.addr())) - .event_listener_factory(events.clone()) - .build() - .expect("client"); - - let error = with_trace_capture(&trace, async { - let response = client - .execute(empty_request(format!( - "http://openwire.test:{}/broken", - server.addr().port() - ))) - .await - .expect("response"); - assert_eq!(response.status(), StatusCode::OK); - - response - .into_body() - .text() - .await - .expect_err("body should fail") - }) - .await; - assert_eq!(error.kind(), WireErrorKind::Protocol); - - let events = events.events(); - assert_event_subsequence( - &events, - &[ - "call_start GET", - "response_headers_end 200 OK", - "response_body_failed protocol", - "connection_released ", - "call_failed Protocol", - ], - ); - assert!( - !events - .iter() - .any(|event| event.starts_with("response_body_end ")), - "events = {events:?}", - ); - - let body_failure = trace - .event_by_message("response body failed") - .expect("body failure trace event"); - assert_eq!( - body_failure.fields.get("error_kind").map(String::as_str), - Some("protocol") - ); - assert_eq!( - body_failure.fields.get("bytes_read").map(String::as_str), - Some("3") - ); - assert_eq!( - body_failure.fields.get("attempt").map(String::as_str), - Some("1") - ); - assert!( - body_failure.fields.contains_key("call_id"), - "body failure event = {body_failure:?}", - ); -} - #[tokio::test] async fn call_timeout_can_fail_during_body_read() { let server = spawn_raw_http1_headers_then_stall_body(Duration::from_millis(200)).await; diff --git a/crates/openwire/tests/tracing.rs b/crates/openwire/tests/tracing.rs new file mode 100644 index 0000000..2eabaf9 --- /dev/null +++ b/crates/openwire/tests/tracing.rs @@ -0,0 +1,458 @@ +//! Each scoped capture scenario runs alone in a fresh process. The parent +//! harness remains parallel; dispatcher/callsite caches cannot cross the boundary. + +mod support; + +use std::future::Future; +use std::process::{Command, Stdio}; +use std::time::Duration; + +use http::{Request, Response, StatusCode}; +use hyper::body::Incoming; +use openwire::{Client, WireErrorKind}; +use openwire_test::{ok_text, spawn_http1, RecordingEventListenerFactory, StaticDnsResolver}; +use tracing_subscriber::prelude::*; + +use support::*; + +const CHILD_SCENARIO: &str = "OPENWIRE_TRACING_TEST_SCENARIO"; +const PARENT_PID: &str = "OPENWIRE_TRACING_TEST_PARENT_PID"; +const COMPLETED: &str = "OPENWIRE_TRACING_SCENARIO_COMPLETED"; + +fn is_child_scenario(name: &str) -> bool { + std::env::var_os(CHILD_SCENARIO).as_deref() == Some(std::ffi::OsStr::new(name)) +} + +fn run_isolated_tracing_test(name: &str, scenario: impl Future) { + if is_child_scenario(name) { + let parent_pid = std::env::var(PARENT_PID) + .expect("parent PID supplied by tracing launcher") + .parse::() + .expect("numeric parent PID"); + assert_ne!( + std::process::id(), + parent_pid, + "capture must run in a fresh process" + ); + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("child Tokio runtime"); + runtime.block_on(async { + tokio::time::timeout(Duration::from_secs(30), scenario) + .await + .expect("tracing scenario must make progress"); + }); + println!("{COMPLETED} {name} pid={}", std::process::id()); + } else if let Err(error) = run_child_scenario(name) { + panic!("{error}"); + } +} + +fn run_child_scenario(name: &str) -> Result<(), String> { + let executable = + std::env::current_exe().map_err(|error| format!("test executable: {error}"))?; + let child = Command::new(executable) + .args(["--exact", name, "--nocapture"]) + .env(CHILD_SCENARIO, name) + .env(PARENT_PID, std::process::id().to_string()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .map_err(|error| format!("launch tracing scenario {name:?}: {error}"))?; + let pid = child.id(); + let output = child + .wait_with_output() + .map_err(|error| format!("wait for tracing scenario {name:?}: {error}"))?; + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + if !output.status.success() { + return Err(format!( + "tracing scenario {name:?} failed ({})\nstdout:\n{stdout}\nstderr:\n{stderr}", + output.status + )); + } + let completed = format!("{COMPLETED} {name} pid={pid}"); + if !stdout.contains(&completed) { + return Err(format!("tracing scenario {name:?} did not complete its selected scenario\nstdout:\n{stdout}\nstderr:\n{stderr}")); + } + Ok(()) +} + +#[test] +fn tracing_attempt_spans_record_stable_connection_reuse_fields() { + run_isolated_tracing_test( + "tracing_attempt_spans_record_stable_connection_reuse_fields", + async { + let server = spawn_http1(|_request| async move { ok_text("pooled") }).await; + let trace = TraceCapture::default(); + let client = Client::builder().build().expect("client"); + + with_trace_capture(&trace, async { + let response = client + .execute(empty_request(server.http_url("/first"))) + .await + .expect("response"); + let _ = response.into_body().text().await.expect("body"); + + let response = client + .execute(empty_request(server.http_url("/second"))) + .await + .expect("response"); + let _ = response.into_body().text().await.expect("body"); + }) + .await; + + let spans = trace.spans_named("openwire.attempt"); + assert_eq!(spans.len(), 2, "spans = {spans:?}"); + assert_eq!( + spans[0].fields.get("attempt").map(String::as_str), + Some("1") + ); + assert_eq!( + spans[0].fields.get("retry_count").map(String::as_str), + Some("0") + ); + assert_eq!( + spans[0].fields.get("redirect_count").map(String::as_str), + Some("0") + ); + assert_eq!( + spans[0].fields.get("auth_count").map(String::as_str), + Some("0") + ); + assert_eq!( + spans[0].fields.get("pool_hit").map(String::as_str), + Some("false") + ); + assert!(!spans[0].fields.contains_key("pool_connection_id")); + assert_eq!( + spans[0].fields.get("connection_reused").map(String::as_str), + Some("false") + ); + assert_eq!( + spans[1].fields.get("attempt").map(String::as_str), + Some("1") + ); + assert_eq!( + spans[1].fields.get("auth_count").map(String::as_str), + Some("0") + ); + assert_eq!( + spans[1].fields.get("pool_hit").map(String::as_str), + Some("true") + ); + assert_eq!( + spans[1].fields.get("pool_connection_id"), + spans[1].fields.get("connection_id"), + "spans = {spans:?}", + ); + assert_eq!( + spans[1].fields.get("connection_reused").map(String::as_str), + Some("true") + ); + assert_eq!( + spans[0].fields.get("connection_id"), + spans[1].fields.get("connection_id"), + "spans = {spans:?}", + ); + }, + ); +} + +#[test] +fn retry_and_redirect_events_follow_stable_order_and_trace_fields() { + run_isolated_tracing_test( + "retry_and_redirect_events_follow_stable_order_and_trace_fields", + async { + let server = spawn_http1(|request: Request| async move { + match request.uri().path() { + "/redirect-after-retry" => Response::builder() + .status(StatusCode::FOUND) + .header("location", "/redirect-target") + .body(http_body_util::Full::new(bytes::Bytes::new())) + .expect("redirect response"), + _ => ok_text("redirect after retry"), + } + }) + .await; + + let connector = FailingTcpConnector::new(1); + let events = RecordingEventListenerFactory::default(); + let trace = TraceCapture::default(); + + let client = Client::builder() + .dns_resolver(StaticDnsResolver::new(server.addr())) + .tcp_connector(connector) + .event_listener_factory(events.clone()) + .max_retries(1) + .build() + .expect("client"); + + with_trace_capture(&trace, async { + let response = client + .execute(empty_request(format!( + "http://openwire.test:{}/redirect-after-retry", + server.addr().port() + ))) + .await + .expect("response"); + let _ = response.into_body().text().await.expect("body"); + }) + .await; + + let events = events.events(); + assert_event_subsequence( + &events, + &[ + "call_start GET", + "connect_failed ", + "retry 1 connect", + "connect_end ", + "connection_acquired ", + "response_headers_end 302 Found", + // Intermediate redirect body is drained so the connection can be + // reused before the follow-up hop starts. + "response_body_end ", + "connection_released ", + "redirect 1 http://openwire.test:", + "connection_acquired ", + "response_headers_end 200 OK", + "response_body_end 20", + "connection_released ", + "call_end", + ], + ); + + let retry_event = trace + .event_by_message("retrying request after connection-establishment failure") + .or_else(|| trace.event_with_field("retry_reason", "connect")) + .unwrap_or_else(|| { + panic!( + "retry trace event missing; captured messages = {:?}", + trace.event_messages() + ) + }); + assert_eq!( + retry_event.fields.get("attempt").map(String::as_str), + Some("2") + ); + assert_eq!( + retry_event.fields.get("retry_count").map(String::as_str), + Some("1") + ); + assert_eq!( + retry_event.fields.get("redirect_count").map(String::as_str), + Some("0") + ); + assert_eq!( + retry_event.fields.get("auth_count").map(String::as_str), + Some("0") + ); + assert_eq!( + retry_event + .fields + .get("retry_reason") + .map(|value| normalize_trace_message(value)), + Some("connect".to_owned()) + ); + + let redirect_event = trace + .event_by_message("following redirect") + .or_else(|| { + trace + .inner + .lock() + .expect("trace capture lock") + .events + .iter() + .find(|event| event.fields.contains_key("redirect_location")) + .cloned() + }) + .unwrap_or_else(|| { + panic!( + "redirect trace event missing; captured messages = {:?}", + trace.event_messages() + ) + }); + assert_eq!( + redirect_event.fields.get("attempt").map(String::as_str), + Some("3") + ); + assert_eq!( + redirect_event.fields.get("retry_count").map(String::as_str), + Some("1") + ); + assert_eq!( + redirect_event + .fields + .get("redirect_count") + .map(String::as_str), + Some("1") + ); + assert_eq!( + redirect_event.fields.get("auth_count").map(String::as_str), + Some("0") + ); + assert!( + redirect_event + .fields + .get("redirect_location") + .is_some_and(|location| location.contains("/redirect-target")), + "redirect event = {redirect_event:?}", + ); + }, + ); +} + +#[test] +fn response_body_failures_emit_call_failed_but_not_response_body_end() { + run_isolated_tracing_test( + "response_body_failures_emit_call_failed_but_not_response_body_end", + async { + let server = spawn_raw_http1_response( + b"HTTP/1.1 200 OK\r\nContent-Length: 5\r\nConnection: close\r\n\r\nabc".to_vec(), + ) + .await; + let events = RecordingEventListenerFactory::default(); + let trace = TraceCapture::default(); + + let client = Client::builder() + .dns_resolver(StaticDnsResolver::new(server.addr())) + .event_listener_factory(events.clone()) + .build() + .expect("client"); + + let error = with_trace_capture(&trace, async { + let response = client + .execute(empty_request(format!( + "http://openwire.test:{}/broken", + server.addr().port() + ))) + .await + .expect("response"); + assert_eq!(response.status(), StatusCode::OK); + + response + .into_body() + .text() + .await + .expect_err("body should fail") + }) + .await; + assert_eq!(error.kind(), WireErrorKind::Protocol); + + let events = events.events(); + assert_event_subsequence( + &events, + &[ + "call_start GET", + "response_headers_end 200 OK", + "response_body_failed protocol", + "connection_released ", + "call_failed Protocol", + ], + ); + assert!( + !events + .iter() + .any(|event| event.starts_with("response_body_end ")), + "events = {events:?}", + ); + + let body_failure = trace + .event_by_message("response body failed") + .expect("body failure trace event"); + assert_eq!( + body_failure.fields.get("error_kind").map(String::as_str), + Some("protocol") + ); + assert_eq!( + body_failure.fields.get("bytes_read").map(String::as_str), + Some("3") + ); + assert_eq!( + body_failure.fields.get("attempt").map(String::as_str), + Some("1") + ); + assert!( + body_failure.fields.contains_key("call_id"), + "body failure event = {body_failure:?}", + ); + }, + ); +} + +fn isolation_probe() { + let span = tracing::debug_span!( + "openwire.test.isolation_probe", + process_id = u64::from(std::process::id()), + ); + let _entered = span.enter(); + tracing::debug!( + process_id = u64::from(std::process::id()), + "isolated tracing probe", + ); +} + +#[test] +fn capture_is_isolated_from_parent_callsite_registration() { + const NAME: &str = "capture_is_isolated_from_parent_callsite_registration"; + // Force a first use in an uncaptured parent thread while TRACE is enabled. + // Its process-wide callsite state must have no effect on the child. We do + // not assert the dependency's buggy parent result, so an upstream repair + // will not invalidate this isolation contract. + let _parent_dispatch = if !is_child_scenario(NAME) { + let dispatch = tracing::Dispatch::new( + tracing_subscriber::registry().with(tracing_subscriber::filter::LevelFilter::TRACE), + ); + std::thread::spawn(isolation_probe) + .join() + .expect("uncaptured parent probe"); + Some(dispatch) + } else { + None + }; + run_isolated_tracing_test(NAME, async { + let trace = TraceCapture::default(); + with_trace_capture(&trace, async { isolation_probe() }).await; + let spans = trace.spans_named("openwire.test.isolation_probe"); + assert_eq!(spans.len(), 1, "one captured child probe: {spans:?}"); + let pid = std::process::id().to_string(); + assert_eq!(spans[0].fields.get("process_id"), Some(&pid)); + let event = trace + .event_by_message("isolated tracing probe") + .expect("child event"); + assert_eq!(event.fields.get("process_id"), Some(&pid)); + assert_eq!( + trace + .event_messages() + .iter() + .filter(|message| normalize_trace_message(message) == "isolated tracing probe") + .count(), + 1, + ); + }); +} + +#[test] +fn launcher_reports_child_failure_diagnostics() { + const NAME: &str = "launcher_reports_child_failure_diagnostics"; + if is_child_scenario(NAME) { + panic!("intentional child diagnostic"); + } + let error = run_child_scenario(NAME).expect_err("a failing scenario cannot pass its parent"); + assert!(error.contains("intentional child diagnostic"), "{error}"); + assert!(error.contains("stdout:"), "{error}"); + assert!(error.contains("stderr:"), "{error}"); +} + +#[test] +fn launcher_rejects_a_filter_that_selects_no_scenario() { + let error = run_child_scenario("not_an_openwire_tracing_scenario") + .expect_err("zero selected tests cannot count as a successful capture"); + assert!( + error.contains("did not complete its selected scenario"), + "{error}" + ); +} diff --git a/docs/testing.md b/docs/testing.md index 56c4570..8e6dce4 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -121,6 +121,15 @@ weekly schedule. Deferred public-origin follow-ons stay in One server per test. Bind port `0`. Prefer these helpers over third-party mock HTTP crates. +Scoped tracing assertions live in `crates/openwire/tests/tracing.rs`. Each case +runs alone in a fresh copy of that test executable; its parent uses `--exact` +and checks both the exit status and a scenario completion marker. This isolates +tracing's process-wide dispatcher/callsite cache from unrelated test threads +while the normal test runner stays parallel. Keep future tracing-capture cases +in this binary and use `run_isolated_tracing_test`; the capture-only async lock +is insufficient. See [tracing-test-isolation.md](tracing-test-isolation.md) for +the failure evidence and regression checks. + ```rust let server = MockWebServer::http1().await; server.enqueue(MockResponse::new().status(StatusCode::FOUND).header("Location", "/next")); diff --git a/docs/tracing-test-isolation.md b/docs/tracing-test-isolation.md new file mode 100644 index 0000000..5bd0dda --- /dev/null +++ b/docs/tracing-test-isolation.md @@ -0,0 +1,107 @@ +# Tracing Test Isolation Fixes + +Status: implemented and verified on macOS arm64 with Rust 1.99.1. +Base: `e74fa27337b605ce1ad246e4851fcec30e798354`; independent of the Age repair in PR #82. + +Issue 1 [P1]: Isolate scoped tracing capture from parallel callsite registration + +File: `crates/openwire/tests/support/harness.rs` — `with_trace_capture` and +`trace_test_lock` (baseline lines 2413–2430). + +Problem: `tracing_attempt_spans_record_stable_connection_reuse_fields` +(`tests/events.rs`, baseline lines 210–291) can capture no spans in a parallel +run. This was reproduced on unmodified main (10 passed, one failed). +[PR #82's macOS default-feature CI](https://github.com/peterich-rs/openwire/actions/runs/43404057007/job/131813850616) +also lost the body-failure trace event in `timeout_cancel.rs` (19 passed, +one failed). The lock only excludes other capture tests; ordinary +HTTP tests still register the same production callsites in this process. + +In tracing-core 0.1.36, `Dispatchers::rebuilder` (`callsite.rs`, lines 544–547) +chooses `JustOne` when one subscriber is registered; its `for_each` (lines +562–566) queries the current thread's dispatcher. A cold callsite registered by +an uncaptured test thread can therefore retain `Interest::never()` for a later +captured request. See the [official versioned source](https://docs.rs/tracing-core/0.1.36/src/tracing_core/callsite.rs.html). + +Approach — Run each capture scenario in a fresh test process: + +Move the three integration capture scenarios into `tests/tracing.rs`. Each +parent test invokes its own executable with `--exact` and the scenario name; +a private child marker executes the scenario once in a Tokio runtime. Verify +the parent/child process boundary, successful child completion, and a completion +marker so a misspelled filter cannot silently pass with zero selected tests. +Forward child output on failure. + +A process boundary removes shared dispatcher/callsite state between unrelated +scenarios while the parent tests remain parallel. Merely locking capture tests +does not exclude ordinary tests. A temporary second dispatcher or rebuilding +the interest cache does not exclude an already in-flight cold registration. +Global single-thread testing hides the test-isolation defect and is not the fix. + +The private helper in `tests/tracing.rs` (line 26) is: + +```rust +fn run_isolated_tracing_test(name: &str, scenario: impl std::future::Future) +``` + +Structural changes: + +- Move the two capture cases from `tests/events.rs` and the body-failure capture + case from `tests/timeout_cancel.rs` into the new tracing test binary. +- Remove the obsolete capture-only async lock from `tests/support/harness.rs`. +- Keep scoped capture and all production code, dependencies and CI parallelism. +- The synchronous unit capture case in `src/transport/tests.rs` (baseline line + 146) uses a callsite unique to that one test, so it does not share the cold + registration window and remains unchanged. + +Existing test adjustments: + +- `tracing_attempt_spans_record_stable_connection_reuse_fields` + (`tests/events.rs`:210): preserve all field/reuse assertions in the child. +- `retry_and_redirect_events_follow_stable_order_and_trace_fields` + (`tests/events.rs`:400): preserve event ordering and retry/redirect fields. +- `response_body_failures_emit_call_failed_but_not_response_body_end` + (`tests/timeout_cancel.rs`:555): preserve failure, lifecycle and byte-count + assertions; only the execution location changes. + +New tests: + +- `capture_is_isolated_from_parent_callsite_registration` (`tests/tracing.rs`:399): + prime a static trace probe in the parent without a capturing default while + a TRACE dispatcher is registered, then capture that probe in the child. + Assert one span/event and the child PID, demonstrating state isolation. +- `run_child_scenario` (`tests/tracing.rs`:52) requires a child-completion + marker containing the selected name and actual child PID. A successful exit + with zero selected tests cannot count as a capture. +- `launcher_reports_child_failure_diagnostics` (`tests/tracing.rs`:439): run + an intentional child panic and check that its diagnostic reaches the parent. +- `launcher_rejects_a_filter_that_selects_no_scenario` (`tests/tracing.rs`:451): + a missing test name must fail despite the child's successful zero-test exit. + +Verification + +- Run the tracing binary with its default parallel test runner and multiple + threads. Causal isolation assertions are the proof; repeats are stress only. +- Run workspace default/all-feature tests with normal parallelism, doctests, + formatting and clippy. +- Update `docs/testing.md` with the capture-only process boundary. No network + protocol behavior or production tracing contract changes; no RFC change. +- The three migrated scenario bodies were compared with main after ignoring + whitespace and the removed lock; all original assertions and actions remain. + +Results (normal parallel test runners; no RUST_TEST_THREADS override): + +| Command | Result | +| --- | --- | +| `cargo test --workspace --all-targets` | 567 passed, 16 ignored; benchmark/example targets completed | +| `cargo test --workspace --all-targets --all-features` | 608 passed, 16 ignored; benchmark/example targets completed | +| `cargo test --workspace --all-features --doc` | 2 passed | +| `cargo test -p openwire --test events --test timeout_cancel --test tracing -- --test-threads=8` | 34 passed; 10 further fresh-process rounds also passed (340 cases) | +| `cargo clippy --workspace --all-targets -- -D warnings` | passed | +| `cargo fmt --all --check` | passed | + +Local commands used a shared CARGO_TARGET_DIR and CARGO_INCREMENTAL=0 to avoid +regenerable build-cache duplication; no test scheduling behavior was overridden. +The complete suites exercise all normal parallel tests. PID checks and the cold +probe provide structural isolation evidence; repeated runs are stress evidence, +not the proof of isolation. Production code, public API and dependencies are +unchanged. Desktop CI on other operating systems supplies separate evidence.