From 8a979358e8ffd920ade677e41c6cbdaf4503d830 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 5 Oct 2026 13:40:33 -0700 Subject: [PATCH 1/4] quest: claim test-flakes-2/warn-capture Co-Authored-By: Grok 4.7 From 7199fefbe50fd2685f2bba9333aff00435924750 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 5 Oct 2026 13:53:11 -0700 Subject: [PATCH 2/4] test(net): count drop WARNs on the emitting thread A scoped subscriber lets a parallel test reach the WARN callsite first and cache it as disabled for the whole process, so drop_unfinished_warns sees zero. One process-global subscriber keeps that interest stable, and a thread-local capture counts only this test's WARNs. Co-Authored-By: Grok 4.7 --- rs/moq-net/src/model/test_tracing.rs | 37 ++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/rs/moq-net/src/model/test_tracing.rs b/rs/moq-net/src/model/test_tracing.rs index c1d315f1032..165355e6903 100644 --- a/rs/moq-net/src/model/test_tracing.rs +++ b/rs/moq-net/src/model/test_tracing.rs @@ -4,6 +4,7 @@ use std::cell::RefCell; use std::sync::Once; use tracing::field::{Field, Visit}; +use tracing::level_filters::LevelFilter; use tracing::span::{Attributes, Id, Record}; use tracing::{Event, Level, Metadata, Subscriber}; @@ -17,19 +18,31 @@ thread_local! { static CAPTURE: RefCell> = const { RefCell::new(None) }; } +/// Clears this thread's capture on unwind so the next one is not nested into a stale slot. +struct Clear; + +impl Drop for Clear { + fn drop(&mut self) { + let _ = CAPTURE.take(); + } +} + /// Count WARN events emitted on this thread whose `message` field contains `expected_message` /// while running `f`. /// -/// The subscriber is process-global rather than scoped with `with_default`: tracing caches each -/// callsite's interest process-wide, so a parallel test reaching the WARN first on a thread -/// without a scoped subscriber disables it for every thread. Counting per thread keeps another -/// test's WARNs out. +/// The subscriber is process-global rather than scoped with `with_default`. Tracing caches each +/// callsite's interest for the whole process, and a single scoped dispatcher rebuilds that cache +/// from the current thread's default. A parallel test that reaches the WARN first, on a thread +/// with no subscriber, caches it as disabled, and this capture then sees nothing. One global +/// subscriber keeps every thread's interest the same. The thread-local slot is what keeps another +/// test's WARNs out of the count. pub(crate) fn count_drop_warnings(expected_message: &str, f: impl FnOnce()) -> usize { static INSTALL: Once = Once::new(); - INSTALL.call_once(|| tracing::subscriber::set_global_default(Warns).expect("no other global subscriber")); - // A callsite first reached on another thread while the install above was still publishing - // sees no subscriber and is cached as disabled. Every capture starts after the install has - // completed, so rebuilding here re-enables it against the now-global subscriber. + INSTALL.call_once(|| { + tracing::subscriber::set_global_default(Warns).expect("no other global subscriber"); + }); + // A callsite first reached while the install above was still publishing sees no subscriber + // and is cached as disabled. Rebuilding after the install has completed re-enables it. tracing::callsite::rebuild_interest_cache(); let capture = Capture { @@ -38,6 +51,7 @@ pub(crate) fn count_drop_warnings(expected_message: &str, f: impl FnOnce()) -> u }; let prev = CAPTURE.replace(Some(capture)); assert!(prev.is_none(), "count_drop_warnings does not nest"); + let _clear = Clear; f(); @@ -52,6 +66,12 @@ impl Subscriber for Warns { *metadata.level() == Level::WARN } + fn max_level_hint(&self) -> Option { + // `None` is treated as "may enable every level", which would turn trace on for the rest + // of the process. This subscriber only records WARN. + Some(LevelFilter::WARN) + } + fn new_span(&self, _span: &Attributes<'_>) -> Id { Id::from_u64(1) } @@ -98,6 +118,7 @@ impl Visit for Msg<'_> { } } +#[cfg(test)] mod tests { use super::count_drop_warnings; From 29eadba76337517d70ba871a2db2f0d2b9da1973 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 6 Oct 2026 02:59:51 -0700 Subject: [PATCH 3/4] test(net): correct the WARN subscriber hint comment None leaves the global max level at TRACE, so level checks miss the static fast path. It does not emit TRACE. Drop the cfg(test) on a module that is already test-only. Co-Authored-By: Grok 4.7 --- rs/moq-net/src/model/test_tracing.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rs/moq-net/src/model/test_tracing.rs b/rs/moq-net/src/model/test_tracing.rs index 165355e6903..f79e8b541d8 100644 --- a/rs/moq-net/src/model/test_tracing.rs +++ b/rs/moq-net/src/model/test_tracing.rs @@ -67,8 +67,8 @@ impl Subscriber for Warns { } fn max_level_hint(&self) -> Option { - // `None` is treated as "may enable every level", which would turn trace on for the rest - // of the process. This subscriber only records WARN. + // `None` leaves the global max level at TRACE, so every level check falls through to + // the callsite cache. This subscriber only records WARN. Some(LevelFilter::WARN) } @@ -118,7 +118,6 @@ impl Visit for Msg<'_> { } } -#[cfg(test)] mod tests { use super::count_drop_warnings; From 924e53e44d4a2710fbb8135923c65f4bdd6f90b2 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 6 Oct 2026 04:02:07 -0700 Subject: [PATCH 4/4] test(net): pin that an unwinding capture clears its slot A panic inside count_drop_warnings must not leave the thread-local capture set, or the next call on that thread looks nested. Co-Authored-By: Grok 4.7 --- rs/moq-net/src/model/test_tracing.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rs/moq-net/src/model/test_tracing.rs b/rs/moq-net/src/model/test_tracing.rs index f79e8b541d8..1f3e8ccdbad 100644 --- a/rs/moq-net/src/model/test_tracing.rs +++ b/rs/moq-net/src/model/test_tracing.rs @@ -135,4 +135,16 @@ mod tests { }); assert_eq!(warns, 1); } + + /// A panic inside the capture must clear the slot, or the next capture on this thread looks nested. + #[test] + fn an_unwind_clears_the_capture() { + let panicked = std::panic::catch_unwind(|| { + count_drop_warnings("test_tracing probe", || panic!("unwind the capture")); + }); + assert!(panicked.is_err()); + + let warns = count_drop_warnings("test_tracing probe", probe); + assert_eq!(warns, 1); + } }