summaryrefslogtreecommitdiffstats
path: root/tests/vcs.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 20:27:26 +0000
committeraur-build <aur-build@localhost>2026-11-19 20:27:26 +0000
commit3cb78f6bc988beaf0408100a1425c02933d8957f (patch)
tree1130d54d02369050aaeda7017b89934d576b787f /tests/vcs.rs
parentf139b9ae0e8d98dc98e1dec6bb0fc427d36ccefa (diff)
downloadaur-build-3cb78f6bc988beaf0408100a1425c02933d8957f.tar.gz
aur-build-3cb78f6bc988beaf0408100a1425c02933d8957f.zip
tests: wait on the condition instead of on the clock
The dispatch and crash waits polled every 50ms and 25ms against a dispatcher that ticks every two seconds; live.rs staged its log appends with 400ms sleeps; vcs.rs waited 80ms to conclude that a blocked racer had not entered. The pool tests take the virtual clock and poll a 2ms condition wait, live.rs appends without sleeping at all, and the Stage B test queues every racer on the slot before releasing it, so the window a broken cap would slip through is set up rather than hoped for. live.rs no longer proves delivery mid-stream, because it never could: the stream response is buffered until it ends, so the sleeps were not observable. Worth fixing on the serving side, but that is a behaviour change, not a test one.
Diffstat (limited to 'tests/vcs.rs')
-rw-r--r--tests/vcs.rs40
1 files changed, 26 insertions, 14 deletions
diff --git a/tests/vcs.rs b/tests/vcs.rs
index e41adfd..52f4372 100644
--- a/tests/vcs.rs
+++ b/tests/vcs.rs
@@ -117,22 +117,34 @@ fn stage_b_is_cached_on_pkgbase_recipe_and_tip() {
#[test]
fn stage_b_concurrency_cap_is_enforced() {
let (env, _fx) = env_with_fixture("git-sourced");
- let slots = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
- let s1 = slots.clone();
+ use std::sync::atomic::{AtomicUsize, Ordering};
+ let inside = std::sync::Arc::new(AtomicUsize::new(0));
+ let attempted = std::sync::Arc::new(AtomicUsize::new(0));
let held = upstream::StageBSlot::acquire(1);
- let entered = std::thread::spawn(move || {
- let _g = upstream::StageBSlot::acquire(1);
- s1.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
- });
- std::thread::sleep(std::time::Duration::from_millis(80));
- assert_eq!(
- slots.load(std::sync::atomic::Ordering::SeqCst),
- 0,
- "a second Stage B entered while the only slot was held"
- );
+ let racers: Vec<_> = (0..3)
+ .map(|_| {
+ let inside = inside.clone();
+ let attempted = attempted.clone();
+ std::thread::spawn(move || {
+ attempted.fetch_add(1, Ordering::SeqCst);
+ let _slot = upstream::StageBSlot::acquire(1);
+ let n = inside.fetch_add(1, Ordering::SeqCst) + 1;
+ assert_eq!(n, 1, "two Stage B runs held the only slot at once");
+ inside.fetch_sub(1, Ordering::SeqCst);
+ })
+ })
+ .collect();
+ // Every racer is queued on the slot before it is released, so a cap that
+ // leaked would let them all in at once rather than by luck of scheduling.
+ while attempted.load(Ordering::SeqCst) < 3 {
+ std::thread::yield_now();
+ }
+ assert_eq!(inside.load(Ordering::SeqCst), 0, "a second Stage B entered while the only slot was held");
drop(held);
- entered.join().unwrap();
- assert_eq!(slots.load(std::sync::atomic::Ordering::SeqCst), 1);
+ for r in racers {
+ r.join().unwrap();
+ }
+ assert_eq!(inside.load(Ordering::SeqCst), 0);
let _ = env;
}