mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
b96fc594ba
commit
1242c76794
1 changed files with 3 additions and 1 deletions
|
|
@ -1451,7 +1451,9 @@ func noAlloc(t *testing.T, n int, f func(int)) {
|
||||||
for j := 0; j < n; j++ {
|
for j := 0; j < n; j++ {
|
||||||
f(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)
|
t.Fatalf("%d mallocs after %d iterations", runtime.MemStats.Mallocs, n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue