wai: a from-rest burst asserted a 2 ms race, and linux-arm64 called it #192
1 changed files with 30 additions and 5 deletions
|
|
@ -1121,10 +1121,26 @@ mod tests {
|
|||
std::thread::sleep(std::time::Duration::from_millis(2));
|
||||
},
|
||||
move || {
|
||||
// Called as the window opens: the workers may have begun the
|
||||
// first unit, but none has completed one.
|
||||
// Called as the window opens. How many units have *begun* by
|
||||
// this instant is a race this test does not control, and it
|
||||
// used to be asserted: `begun <= 3`, one per worker.
|
||||
//
|
||||
// Nothing in `burst_from_rest` entails that. Each worker, once
|
||||
// the barrier releases, increments this counter and sleeps 2 ms;
|
||||
// the caller then calls this closure. For `begun` to exceed the
|
||||
// worker count, the caller need only be descheduled for longer
|
||||
// than that 2 ms at exactly this point — which a contended host
|
||||
// will do, and did: the assertion failed on the linux-arm64
|
||||
// runner (a VM on a box at load 173) while passing on every
|
||||
// other platform. It is a 2 ms race, not a property.
|
||||
//
|
||||
// Recorded, not asserted. What the test establishes about
|
||||
// starting from rest is asserted below and does not depend on
|
||||
// this ordering: the window opened `FromRest`, every worker was
|
||||
// in flight, and completions never exceed starts by more than
|
||||
// the worker count.
|
||||
let begun = at_open.load(Ordering::SeqCst);
|
||||
assert!(begun <= 3, "no more than one unit per worker can have begun");
|
||||
eprintln!("from-rest burst: {begun} unit(s) had begun as the window opened");
|
||||
std::thread::sleep(std::time::Duration::from_millis(40));
|
||||
vec![1.0, 2.0]
|
||||
},
|
||||
|
|
@ -1133,9 +1149,18 @@ mod tests {
|
|||
assert_eq!(count.in_flight, 3);
|
||||
assert!(count.completions > 0 && window_s > 0.0);
|
||||
// Every completion started inside the window: completions can never
|
||||
// exceed starts, and starts exceed completions by at most N.
|
||||
// exceed starts, and starts exceed completions by at most N — the
|
||||
// in-flight units — plus the N a worker may begin between the window
|
||||
// closing and this read. This is the test's real claim, and unlike the
|
||||
// count at window-open it holds however the host schedules the threads:
|
||||
// it bounds a difference by the worker count rather than asserting that
|
||||
// a particular instant arrived before a 2 ms sleep finished.
|
||||
let starts = started.load(Ordering::SeqCst);
|
||||
assert!(count.completions <= starts && starts <= count.completions + 3 + 3);
|
||||
assert!(
|
||||
count.completions <= starts && starts <= count.completions + 3 + 3,
|
||||
"{} completions against {starts} starts with 3 workers",
|
||||
count.completions
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue