From 532889129a4a3eab75a5be9555d59f8d4b174aba Mon Sep 17 00:00:00 2001 From: Ryanmello07 <67509637+Ryanmello07@users.noreply.github.com> Date: Tue, 11 Aug 2026 00:06:24 +0100 Subject: [PATCH] test(bandwidth): widen TestMeasureExcludesWarmup's margin to 2x CI failed on main at 2.965x against a 3x bar. Nothing regressed: on this host the ratio runs 3.19-3.27 unloaded, so 3x was asserting ~94% of what this test's own shape produces, and ordinary runner jitter closes that gap. The ratio is wall clock over steady window. Bytes flow only in the bulk phase -- ~0.67s of a ~2.17s transfer -- and under contention that window stretches faster than the total does, so the ratio falls as the runner slows. Measured here under cgroup CPU limits, 4 runs each: 8 cores 3.19 - 3.25 1.0 cpu 3.24 - 3.27 0.5 cpu 3.17 - 3.23 0.25 cpu 2.40 - 2.73 <- 3x fails from here down 0.15 cpu 1.65 - 1.68 <- 2x fails from here down 2x keeps the property the test exists for. If warmup stopped being excluded, BytesPerSecond would BE the warmup-inclusive rate and the ratio would be 1. Simulating exactly that regression (steadyFrom = start) gives 1.001x, which fails the 2x bar as it should. 2x is a wider margin, not a guarantee: a runner below ~0.2 CPU still falls under it. No fixed multiplier can be robust here, because the ratio degrades continuously toward 1 as the machine slows. Deriving the bound from the measured window would be the structural fix; this change buys about twice the contention headroom without one. Full suite green under the CI command (go test -race -count=1 -timeout 20m ./...); bandwidth alone 6/6 consecutive -race runs. --- bandwidth/bandwidth_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bandwidth/bandwidth_test.go b/bandwidth/bandwidth_test.go index 37403a5..3decc0b 100644 --- a/bandwidth/bandwidth_test.go +++ b/bandwidth/bandwidth_test.go @@ -144,9 +144,28 @@ func TestMeasureExcludesWarmup(t *testing.T) { wallClock, WarmupDuration) } + // The property under test is that the stalled warmup is excluded: if it + // were counted, BytesPerSecond would BE the warmup-inclusive rate and the + // ratio would be 1. Anything comfortably above 1 demonstrates exclusion. + // + // The multiplier is 2, not 3, because 3 sat right on top of what this shape + // produces. The ratio is wall clock over steady window, and bytes flow only + // in the bulk phase -- ~0.67s of a ~2.17s transfer -- so an unloaded run + // lands at 3.19-3.27x, and CI failed at 2.965x. (MaxSteadyInflation caps + // the ratio at 4x above that, but the shape binds first.) Under CPU + // contention the window stretches faster than the total does, so the ratio + // falls further still: 2.40-2.73x at a quarter CPU. A 3x bar therefore + // measures the runner rather than the code. + // + // 2x is a wider margin, not a guarantee -- a runner below ~0.2 CPU still + // falls under it, and no fixed multiplier can be robust when the ratio + // degrades continuously toward 1 as the machine slows. Deriving the bound + // from sample.Elapsed would be the structural fix. What 2x does preserve is + // the only thing this test exists to catch: if warmup stopped being + // excluded the ratio would collapse to ~1.0, which fails loudly here. naive := float64(sample.SampleByteCount) / wallClock.Seconds() - if sample.BytesPerSecond < 3*naive { - t.Errorf("BytesPerSecond = %.0f, want at least 3x the warmup-inclusive rate %.0f -- the stalled first %s is being counted", + if sample.BytesPerSecond < 2*naive { + t.Errorf("BytesPerSecond = %.0f, want at least 2x the warmup-inclusive rate %.0f -- the stalled first %s is being counted", sample.BytesPerSecond, naive, WarmupDuration) } }