Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions sdks/c/src/event_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,14 +752,17 @@ mod phase2_regression_tests {
let canary_after = canary.load(Ordering::Relaxed);
canary_stop.store(1, Ordering::Relaxed);

// The drain takes >=NUM_EVENTS*10ms = 1000ms. The canary should
// have made many ticks during that time IF the producer yielded.
// If push_event_with_capacity busy-spinned, the single worker
// would have been monopolized and the canary would barely advance.
// `boxlite_runtime_drain(rt, 0, …)` empties the queue in bulk, so the
// drainer finishes in ~150-250ms — not the ~1000ms a naive
// "100 events × 10ms" estimate suggests. In that window a cooperative
// producer lets the canary tick ~8-10 times; a producer that busy-spins
// or blocks the single worker instead collapses it to ~2 (measured).
// `>= 5` separates the two with margin on both sides, without sitting on
// the flaky 8-10 boundary the old `>= 10` threshold did.
let progress = canary_after.saturating_sub(canary_before);
assert!(
progress >= 10,
"canary advanced only {progress} ticks; producer likely busy-spinning instead of yielding"
progress >= 5,
"canary advanced only {progress} ticks; producer likely busy-spinning or blocking the worker instead of yielding"
);

unsafe { boxlite_runtime_free(rt_ptr) };
Expand Down
Loading