aboutsummaryrefslogtreecommitdiffstats
path: root/device/device_test.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2021-02-03 08:26:27 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-03 17:45:22 +0100
commit91617b4c522eaa034d39b208edc8221ba52e0954 (patch)
tree9a0a613d027c96ffb082f8f1d415daa19e2f96bd /device/device_test.go
parentdevice: add up/down stress test (diff)
downloadwireguard-go-91617b4c522eaa034d39b208edc8221ba52e0954.tar.xz
wireguard-go-91617b4c522eaa034d39b208edc8221ba52e0954.zip
device: fix goroutine leak test
The leak test had rare flakes. If a system goroutine started at just the wrong moment, you'd get a false positive. Instead of looping until the goroutines look good and then checking, exit completely as soon as the number of goroutines looks good. Also, check more frequently, in an attempt to complete faster. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/device_test.go')
-rw-r--r--device/device_test.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/device/device_test.go b/device/device_test.go
index b783771..50e3dbc 100644
--- a/device/device_test.go
+++ b/device/device_test.go
@@ -405,14 +405,15 @@ func goroutineLeakCheck(t *testing.T) {
return
}
// Give goroutines time to exit, if they need it.
- for i := 0; i < 1000 && startGoroutines < runtime.NumGoroutine(); i++ {
- time.Sleep(10 * time.Millisecond)
- }
- if got := runtime.NumGoroutine(); startGoroutines < got {
- _, endStacks := goroutines()
- t.Logf("starting stacks:\n%s\n", startStacks)
- t.Logf("ending stacks:\n%s\n", endStacks)
- t.Fatalf("expected %d goroutines, got %d, leak?", startGoroutines, got)
+ for i := 0; i < 10000; i++ {
+ if runtime.NumGoroutine() <= startGoroutines {
+ return
+ }
+ time.Sleep(1 * time.Millisecond)
}
+ endGoroutines, endStacks := goroutines()
+ t.Logf("starting stacks:\n%s\n", startStacks)
+ t.Logf("ending stacks:\n%s\n", endStacks)
+ t.Fatalf("expected %d goroutines, got %d, leak?", startGoroutines, endGoroutines)
})
}