Skip to content

Commit b58f391

Browse files
test(server): consolidate worker span regression coverage
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent c412f66 commit b58f391

1 file changed

Lines changed: 14 additions & 31 deletions

File tree

‎crates/openshell-server/src/otel_tracing.rs‎

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,9 @@ mod tests {
691691
let child_context = child.context();
692692
drop(parent);
693693

694-
std::thread::spawn(move || {
694+
let (release, released) = std::sync::mpsc::channel();
695+
let worker = std::thread::spawn(move || {
696+
released.recv().expect("test releases the worker's span");
695697
// Like SQLx, enter the carried span without installing its dispatcher.
696698
let entered = child.enter();
697699
drop(entered);
@@ -701,11 +703,18 @@ mod tests {
701703
// Closing the carried span must also restore the worker's default,
702704
// so unrelated work cannot leak into this test's private exporter.
703705
drop(tracing::info_span!("unrelated_worker_span"));
704-
})
705-
.join()
706-
.expect("worker closes spans without consulting the global registry");
706+
});
707+
708+
assert!(traced.finished_spans().is_empty());
709+
let waiting = traced.wait_for_span("worker_parent");
710+
tokio::pin!(waiting);
711+
assert!(futures::poll!(waiting.as_mut()).is_pending());
707712

708-
let parent = traced.span_named("worker_parent");
713+
release.send(()).unwrap();
714+
let parent = waiting.await;
715+
worker
716+
.join()
717+
.expect("worker closes spans without consulting the global registry");
709718
let child = traced.span_named("worker_child");
710719
test_exporter::assert_is_root(&parent);
711720
assert_eq!(child.parent_span_id, parent.span_context.span_id());
@@ -748,32 +757,6 @@ mod tests {
748757
);
749758
}
750759

751-
#[tokio::test]
752-
async fn tracing_waits_for_worker_held_spans_to_close() {
753-
let traced = test_exporter::install_traced();
754-
let parent = tracing::info_span!("awaited_parent");
755-
let child = tracing::info_span!(parent: &parent, "awaited_child");
756-
drop(parent);
757-
758-
let (release, released) = std::sync::mpsc::channel();
759-
let worker = std::thread::spawn(move || {
760-
released.recv().expect("test releases the worker's span");
761-
drop(child);
762-
});
763-
764-
assert!(traced.finished_spans().is_empty());
765-
let waiting = traced.wait_for_span("awaited_parent");
766-
tokio::pin!(waiting);
767-
assert!(futures::poll!(waiting.as_mut()).is_pending());
768-
769-
release.send(()).unwrap();
770-
let parent = waiting.await;
771-
worker.join().expect("worker closes child and parent");
772-
let child = traced.span_named("awaited_child");
773-
test_exporter::assert_is_root(&parent);
774-
assert_eq!(child.parent_span_id, parent.span_context.span_id());
775-
}
776-
777760
#[tokio::test]
778761
async fn tracing_wait_does_not_lose_closure_between_snapshot_and_await() {
779762
let traced = test_exporter::install_traced();

0 commit comments

Comments
 (0)