Skip to content

Commit 7f4b4ad

Browse files
committed
device: fix slow test and go vet
TestWaitPool now scales better to small hosts, and no longer triggers `go vet`. Signed-off-by: Alex Valiushko <alexvaliushko@tailscale.com> Change-Id: I97a2d22561468de14b17e09d557f212b6a6a6964
1 parent cd4feb8 commit 7f4b4ad

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

device/pools_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import (
1717
func TestWaitPool(t *testing.T) {
1818
var wg sync.WaitGroup
1919
var trials atomic.Int32
20-
startTrials := int32(100000)
20+
n := runtime.NumCPU()
21+
// The original test of 100,000 trials resulted in very long times on small hosts.
22+
// Scaling it down to 100*n^2 results a 1.5s run on a 4-core VM.
23+
startTrials := int32(min(100*n*n, 100000))
2124
if raceEnabled {
2225
// This test can be very slow with -race.
2326
startTrials /= 10
@@ -63,7 +66,7 @@ func TestWaitPool(t *testing.T) {
6366
}
6467
wg.Wait()
6568
if max.Load() != p.max {
66-
t.Errorf("Actual maximum count (%d) != ideal maximum count (%d)", max, p.max)
69+
t.Errorf("Actual maximum count (%d) != ideal maximum count (%d)", max.Load(), p.max)
6770
}
6871
}
6972

0 commit comments

Comments
 (0)