runtime: adjust expected error threshold in TestSelectFairness

Make it a bit more relaxed on the expected fairness, as fastrand()
isn't a truly perfect random number generator.

Fixes #34808

Change-Id: Ib55b2bbe3c1bf63fb4f446fd1291eb1236efc33b
Reviewed-on: https://go-review.googlesource.com/c/go/+/200857
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Giovanni Bajo 2019-10-12 12:05:58 +02:00
parent 592d304bdc
commit e49ecaaa0a
1 changed files with 2 additions and 2 deletions

View File

@ -480,11 +480,11 @@ 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 five nines is 4.4172 / (2 * Sqrt(10000)).
// 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.4172/(2*math.Sqrt(trials)) {
if e > 4.891676/(2*math.Sqrt(trials)) {
t.Errorf("unfair select: in %d trials, results were %d, %d", trials, cnt1, cnt2)
}
close(done)