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 <khr@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Keith Randall 2023-10-31 09:54:54 -07:00 committed by Gopher Robot
parent 962ccbef91
commit b11defeaed
1 changed files with 7 additions and 6 deletions

View File

@ -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)