mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-15 01:05:15 +01:00
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>
This commit is contained in:
parent
7258a8973d
commit
91617b4c52
@ -405,14 +405,15 @@ func goroutineLeakCheck(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Give goroutines time to exit, if they need it.
|
// Give goroutines time to exit, if they need it.
|
||||||
for i := 0; i < 1000 && startGoroutines < runtime.NumGoroutine(); i++ {
|
for i := 0; i < 10000; i++ {
|
||||||
time.Sleep(10 * time.Millisecond)
|
if runtime.NumGoroutine() <= startGoroutines {
|
||||||
}
|
return
|
||||||
if got := runtime.NumGoroutine(); startGoroutines < got {
|
}
|
||||||
_, endStacks := goroutines()
|
time.Sleep(1 * time.Millisecond)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user