Stabilize network policy event capture in concurrent tests (#36779)

## Why

Concurrent tests without a tracing subscriber can cache the network policy
callsite as disabled, causing event-capture tests to miss events.

## What changed

- Attach the test event collector directly to the captured future.
- Rebuild the tracing interest cache before running that future while keeping
  tracing out of its single-subscriber fast path.

GitOrigin-RevId: 20d6160d26f56ad9fd86afd5107cb4313a5fce73
This commit is contained in:
Adam Perry @ OpenAI
2026-08-03 18:18:47 +00:00
committed by copyberry
parent 78306a32af
commit 136f75e7b7

View File

@@ -407,6 +407,7 @@ pub(crate) mod test_support {
use tracing::Subscriber;
use tracing::field::Field;
use tracing::field::Visit;
use tracing::instrument::WithSubscriber;
use tracing::span::Attributes;
use tracing::span::Record;
use tracing::subscriber::Interest;
@@ -531,8 +532,15 @@ pub(crate) mod test_support {
Fut: Future<Output = T>,
{
let collector = EventCollector::default();
let _guard = tracing::subscriber::set_default(collector.clone());
let output = f().await;
// Keep tracing out of its single-subscriber fast path: concurrent tests
// without a subscriber can otherwise cache this callsite as disabled.
let _interest_dispatch = tracing::Dispatch::new(collector.clone());
let output = async {
tracing::callsite::rebuild_interest_cache();
f().await
}
.with_subscriber(collector.clone())
.await;
let events = collector.events();
(output, events)
}