]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: make select fairness test less picky
authorKeith Randall <khr@golang.org>
Tue, 31 Oct 2023 16:54:54 +0000 (09:54 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 31 Oct 2023 20:47:35 +0000 (20:47 +0000)
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>

src/runtime/chan_test.go

index 256f97676ed55c1419e82ca73438a13fd84e0172..526d45bb43013675593ba87265bc0cad176b0741 100644 (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)