From fca7f669f5d1f41817e2ad1c650efb04f1fb49c8 Mon Sep 17 00:00:00 2001 From: damocles Date: Sat, 7 Nov 2026 09:08:04 +0100 Subject: [PATCH] hive-agent: poll, do not sleep, for the positive case in the accept-limit test --- hive-agent/src/todo_server.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hive-agent/src/todo_server.rs b/hive-agent/src/todo_server.rs index a98807cf..4746f5f0 100644 --- a/hive-agent/src/todo_server.rs +++ b/hive-agent/src/todo_server.rs @@ -550,12 +550,26 @@ mod tests { let _a = UnixStream::connect(&path).await.expect("first"); let _b = UnixStream::connect(&path).await.expect("second"); + let reached = |n: usize| { + let started = started.clone(); + async move { + tokio::time::timeout(std::time::Duration::from_secs(5), async { + while started.load(Ordering::SeqCst) < n { + tokio::time::sleep(std::time::Duration::from_millis(10)).await; + } + }) + .await + .is_ok() + } + }; + assert!(reached(1).await, "first was served"); + // The negative case only fails if the cap is broken, so a short wait + // is enough. tokio::time::sleep(std::time::Duration::from_millis(100)).await; assert_eq!(started.load(Ordering::SeqCst), 1, "second waited its turn"); release.notify_one(); - tokio::time::sleep(std::time::Duration::from_millis(100)).await; - assert_eq!(started.load(Ordering::SeqCst), 2, "freed slot admitted it"); + assert!(reached(2).await, "freed slot admitted the second"); server.abort(); }