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