diff options
author | Rob Pike <r@golang.org> | 2011-05-17 11:15:14 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-05-17 11:15:14 -0400 |
commit | 1242c76794936f7bdd4406aa8914500eefe655d4 (patch) | |
tree | b089e7e4212e306fe3d261782738e72fa6960ead | |
parent | b96fc594ba3b61755e784d84ce45bb9a78094bc8 (diff) | |
download | go-1242c76794936f7bdd4406aa8914500eefe655d4.tar.gz go-1242c76794936f7bdd4406aa8914500eefe655d4.zip |
reflect: make allocation test less fragile.
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, rsc
https://golang.org/cl/4533041
-rw-r--r-- | src/pkg/reflect/all_test.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 991d5ca8b7..c83a9b75f6 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -1451,7 +1451,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) } } |