From 3657eef6e4b34c6ad2bda0e22fb4d5626fcc6aab Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 28 May 2026 13:20:44 +0000 Subject: [PATCH] test(ffi): de-flake pump_yields_when_queue_full via threshold recalibration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `progress >= 10` flaked (~40% first-try failure) because the bulk `boxlite_runtime_drain(rt, 0, …)` empties the queue in ~150-250ms, so a cooperative producer only lets the canary tick ~8-10 times — the threshold sat right on that boundary. Measurement shows `yield_now` does not starve the canary (max_gap ~21ms with or without a timer park), so there is no production bug: the flake was pure threshold miscalibration. Lower to `>= 5`, which keeps margin over the cooperative ~8-10 while still catching the regression it guards — a producer that busy-spins / blocks the single worker collapses the canary to ~2 ticks (verified by injecting std::hint::spin_loop() in place of the yield). No production change. Co-Authored-By: Claude Opus 4.7 (1M context) --- sdks/c/src/event_queue.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sdks/c/src/event_queue.rs b/sdks/c/src/event_queue.rs index e9c564362..c9561a6a3 100644 --- a/sdks/c/src/event_queue.rs +++ b/sdks/c/src/event_queue.rs @@ -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) };