]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: make allocation test less fragile.
authorRob Pike <r@golang.org>
Sun, 8 May 2011 15:32:18 +0000 (08:32 -0700)
committerRob Pike <r@golang.org>
Sun, 8 May 2011 15:32:18 +0000 (08:32 -0700)
When GOMAXPROCS>1, the testing framework runs in parallel with the
test itself and may do a small number of allocations, so allow the
"noAllocs" condition to admit just a few.

Fixes #1782.

R=rsc
CC=golang-dev
https://golang.org/cl/4533041

src/pkg/reflect/all_test.go

index dee3f4915bbb3abd154fe6b0a3ba130d93b9ed02..e20e03f501407b01e51381315aca5e14cc00b25b 100644 (file)
@@ -1459,7 +1459,9 @@ func noAlloc(t *testing.T, n int, f func(int)) {
        for j := 0; j < n; j++ {
                f(j)
        }
-       if runtime.MemStats.Mallocs != 0 {
+       // A few allocs may happen in the testing package when GOMAXPROCS > 1, so don't
+       // require zero mallocs.
+       if runtime.MemStats.Mallocs > 5 {
                t.Fatalf("%d mallocs after %d iterations", runtime.MemStats.Mallocs, n)
        }
 }