From: Keith Randall Date: Tue, 31 Oct 2023 16:54:54 +0000 (-0700) Subject: runtime: make select fairness test less picky X-Git-Tag: go1.22rc1~471 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b11defeaed46a56e2d8a32f16ce3e22a93c3a825;p=gostls13.git runtime: make select fairness test less picky Allow up to 10 standard deviations from the mean, instead of ~5 that the current test allows. 10 standard deviations allows up to a 4500/5500 split. Fixes #52465 Change-Id: Icb21c1d31fafbcf4723b75435ba5e98863e812c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/538815 Auto-Submit: Keith Randall Reviewed-by: Bryan Mills Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI --- diff --git a/src/runtime/chan_test.go b/src/runtime/chan_test.go index 256f97676e..526d45bb43 100644 --- a/src/runtime/chan_test.go +++ b/src/runtime/chan_test.go @@ -481,12 +481,13 @@ func TestSelectFairness(t *testing.T) { } // If the select in the goroutine is fair, // cnt1 and cnt2 should be about the same value. - // With 10,000 trials, the expected margin of error at - // a confidence level of six nines is 4.891676 / (2 * Sqrt(10000)). - r := float64(cnt1) / trials - e := math.Abs(r - 0.5) - t.Log(cnt1, cnt2, r, e) - if e > 4.891676/(2*math.Sqrt(trials)) { + // See if we're more than 10 sigma away from the expected value. + // 10 sigma is a lot, but we're ok with some systematic bias as + // long as it isn't too severe. + const mean = trials * 0.5 + const variance = trials * 0.5 * (1 - 0.5) + stddev := math.Sqrt(variance) + if math.Abs(float64(cnt1-mean)) > 10*stddev { t.Errorf("unfair select: in %d trials, results were %d, %d", trials, cnt1, cnt2) } close(done)