From e6720f985df660a058a4228c6cb96c77d9c0b2a8 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Tue, 14 Nov 2023 20:13:56 +0100 Subject: [PATCH] metrics: fix hang in `worker_overflow_count` test (#6146) Closes: #6054 --- tokio/tests/rt_metrics.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tokio/tests/rt_metrics.rs b/tokio/tests/rt_metrics.rs index 42faab37f..38bc18f7b 100644 --- a/tokio/tests/rt_metrics.rs +++ b/tokio/tests/rt_metrics.rs @@ -471,14 +471,17 @@ fn worker_overflow_count() { // First, we need to block the other worker until all tasks have // been spawned. - tokio::spawn(async move { - tx1.send(()).unwrap(); - rx2.recv().unwrap(); + // + // We spawn from outside the runtime to ensure that the other worker + // will pick it up: + // + tokio::task::spawn_blocking(|| { + tokio::spawn(async move { + tx1.send(()).unwrap(); + rx2.recv().unwrap(); + }); }); - // Bump the next-run spawn - tokio::spawn(async {}); - rx1.recv().unwrap(); // Spawn many tasks