summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2011-05-08 08:32:18 -0700
committerRob Pike <r@golang.org>2011-05-08 08:32:18 -0700
commit9d296d25e269e46bff5d44d7bbceab15aceaa6a6 (patch)
tree9e692a69572e62ae43dd2ddd3a59f5d7e4d43f52
parent5d4012ddca542e5d5a410368ee8d201fbcb1880c (diff)
downloadgo-9d296d25e269e46bff5d44d7bbceab15aceaa6a6.tar.gz
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 issue 1782. R=rsc CC=golang-dev http://codereview.appspot.com/4533041
-rw-r--r--src/pkg/reflect/all_test.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go
index dee3f4915..e20e03f50 100644
--- a/src/pkg/reflect/all_test.go
+++ b/src/pkg/reflect/all_test.go
@@ -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)
}
}