Stabilize cancellation and tracing tests (#58171)

## Why

The SIGTERM cleanup test depends on the OS scheduling the shell within the production grace period. Tracing tests also need fixture creation and cleanup to use the appropriate subscriber.

## What changed

- Pause Tokio time while waiting for the shell's cleanup marker, keeping the cancellation future runnable to prevent automatic clock advancement, then resume time after execution.
- Adjust subscriber setup and fixture lifetimes in session and tool dispatch tests so instrumented resources are created and dropped under the appropriate subscriber.

GitOrigin-RevId: 12c654a031a8a4e61fc66488a5f687852f5ca099
This commit is contained in:
aakash-oai
2026-10-29 20:39:04 +00:00
committed by copyberry
parent b5c5d462dc
commit d04071d3ff
4 changed files with 35 additions and 13 deletions
+11 -9
View File
@@ -767,6 +767,17 @@ mod tests {
dynamic: bool,
critical_path_timing: bool,
) -> anyhow::Result<()> {
// Create and drop instrumented session resources under the same subscriber.
// A prior traced test may have installed a different global subscriber.
let buffer: &'static std::sync::Mutex<Vec<u8>> =
Box::leak(Box::new(std::sync::Mutex::new(Vec::new())));
let subscriber = tracing_subscriber::fmt()
.with_ansi(false)
.with_max_level(tracing::Level::INFO)
.with_writer(MockWriter::new(buffer))
.finish();
let _subscriber_guard = tracing::subscriber::set_default(subscriber);
let (session, mut turn_context) = crate::session::tests::make_session_and_context().await;
Arc::make_mut(&mut turn_context.config)
.features
@@ -832,15 +843,6 @@ mod tests {
.expect("test should release the execution gate");
});
let buffer: &'static std::sync::Mutex<Vec<u8>> =
Box::leak(Box::new(std::sync::Mutex::new(Vec::new())));
let subscriber = tracing_subscriber::fmt()
.with_ansi(false)
.with_max_level(tracing::Level::INFO)
.with_writer(MockWriter::new(buffer))
.finish();
let _subscriber_guard = tracing::subscriber::set_default(subscriber);
let cancellation_token = CancellationToken::new();
let call = ToolCall {
tool_name,
@@ -61,8 +61,10 @@ async fn spawned_dispatch_preserves_caller_context(level: LevelFilter) -> anyhow
tracing::Dispatch::new(tracing::subscriber::NoSubscriber::default());
let _subscriber_guard = tracing::subscriber::set_default(subscriber);
async {
// Retain the fixture until its ambient subscriber is restored.
// The unknown-tool result still crosses the real spawned dispatch boundary.
runtime
.clone()
.handle_tool_call(
ToolCall {
tool_name: codex_tools::ToolName::plain("unknown_tool"),