]> Cypherpunks.ru repositories - gostls13.git/commitdiff
test: make maplinear more robust
authorRuss Cox <rsc@golang.org>
Mon, 27 Oct 2014 22:59:02 +0000 (18:59 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 27 Oct 2014 22:59:02 +0000 (18:59 -0400)
The test just doubled a certain number of times
and then gave up. On a mostly fast but occasionally
slow machine this may never make the test run
long enough to see the linear growth.

Change test to keep doubling until the first round
takes at least a full second, to reduce the effect of
occasional scheduling or other jitter.

The failure we saw had a time for the first round
of around 100ms.

Note that this test still passes once it sees a linear
effect, even with a very small total time.
The timeout here only applies to how long the execution
must be to support a reported failure.

LGTM=khr
R=khr
CC=golang-codereviews, rlh
https://golang.org/cl/164070043

test/maplinear.go

index 06da968ef0d9754b2d8c0b2b3693caf72a29259a..34d091491480d741e51288c65ee267582d467afb 100644 (file)
@@ -44,14 +44,21 @@ func checkLinear(typ string, tries int, f func(n int)) {
                        }
                        return
                }
-               fails++
-               if fails == 6 {
+               // If n ops run in under a second and the ratio
+               // doesn't work out, make n bigger, trying to reduce
+               // the effect that a constant amount of overhead has
+               // on the computed ratio.
+               if t1 < 1*time.Second {
+                       n *= 2
+                       continue
+               }
+               // Once the test runs long enough for n ops,
+               // try to get the right ratio at least once.
+               // If five in a row all fail, give up.
+               if fails++; fails >= 5 {
                        panic(fmt.Sprintf("%s: too slow: %d inserts: %v; %d inserts: %v\n",
                                typ, n, t1, 2*n, t2))
                }
-               if fails < 4 {
-                       n *= 2
-               }
        }
 }