all: use testingutil.MinAllocsPerRun

There are a few remaining uses of testing.AllocsPerRun:
Two in which we only log the number of allocations,
and one in which dynamically calculate the allocations
target based on a different AllocsPerRun run.

This also allows us to tighten the "no allocs"
test in wgengine/filter.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder
2021-10-27 16:21:44 -07:00
committed by Josh Bleecher Snyder
parent 1df865a580
commit 94fb42d4b2
11 changed files with 63 additions and 58 deletions

View File

@ -8,6 +8,7 @@ import (
"testing"
"inet.af/netaddr"
"tailscale.com/tstest"
)
func TestCache(t *testing.T) {
@ -67,7 +68,7 @@ func TestCache(t *testing.T) {
wantVal(k3, 30)
wantLen(1)
allocs := int(testing.AllocsPerRun(1000, func() {
err := tstest.MinAllocsPerRun(t, 0, func() {
got, ok := c.Get(k3)
if !ok {
t.Fatal("missing k3")
@ -75,8 +76,8 @@ func TestCache(t *testing.T) {
if got != 30 {
t.Fatalf("got = %d; want 30", got)
}
}))
if allocs != 0 {
t.Errorf("allocs = %v; want 0", allocs)
})
if err != nil {
t.Error(err)
}
}