hive-agent: poll, do not sleep, for the positive case in the accept-limit test
This commit is contained in:
parent
e9940be983
commit
fca7f669f5
1 changed files with 16 additions and 2 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue