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
+5 -4
View File
@@ -628,6 +628,8 @@ fn skill_message(text: &str) -> ResponseItem {
#[tokio::test]
async fn regular_turn_emits_turn_started_with_trace_id_without_waiting_for_startup_prewarm() {
// Prepare filesystem-backed fixtures before replacing the ambient subscriber.
let (sess, _initial_turn, rx) = make_session_and_context_with_rx().await;
let _trace_test_context = install_test_tracing("codex-core-tests");
let request_parent = W3cTraceContext {
traceparent: Some("00-00000000000000000000000000000011-0000000000000022-01".into()),
@@ -638,9 +640,7 @@ async fn regular_turn_emits_turn_started_with_trace_id_without_waiting_for_start
&request_span,
&request_parent
));
let (sess, tc, rx) = make_session_and_context_with_rx()
.instrument(request_span)
.await;
let tc = sess.new_default_turn().instrument(request_span).await;
assert_eq!(
tc.trace_id.as_deref(),
Some("00000000000000000000000000000011")
@@ -8754,6 +8754,8 @@ async fn spawn_task_turn_span_inherits_dispatch_trace_context() {
}
}
// Keep fixture creation and cleanup under the ambient subscriber.
let (sess, tc, rx) = make_session_and_context_with_rx().await;
let _trace_test_context = install_test_tracing("codex-core-tests");
let request_parent = W3cTraceContext {
@@ -8783,7 +8785,6 @@ async fn spawn_task_turn_span_inherits_dispatch_trace_context() {
});
let dispatch_span_id = dispatch_span.context().span().span_context().span_id();
let (sess, tc, rx) = make_session_and_context_with_rx().await;
let captured_trace = Arc::new(std::sync::Mutex::new(None));
async {