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(); }