mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
tstest: make ResourceCheck panic on parallel tests
To find potential flakes earlier. Updates #deflake-effort Change-Id: I52add6111d660821c3a23d4b1dd032821344bc48 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
498f7ec663
commit
f991c8a61f
@ -13,8 +13,19 @@ import (
|
|||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ResourceCheck takes a snapshot of the current goroutines and registers a
|
||||||
|
// cleanup on tb to verify that after the rest, all goroutines created by the
|
||||||
|
// test go away. (well, at least that the count matches. Maybe in the future it
|
||||||
|
// can look at specific routines).
|
||||||
|
//
|
||||||
|
// It panics if called from a parallel test.
|
||||||
func ResourceCheck(tb testing.TB) {
|
func ResourceCheck(tb testing.TB) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
|
// Set an environment variable (anything at all) just for the
|
||||||
|
// side effect of tb.Setenv panicking if we're in a parallel test.
|
||||||
|
tb.Setenv("TS_CHECKING_RESOURCES", "1")
|
||||||
|
|
||||||
startN, startStacks := goroutines()
|
startN, startStacks := goroutines()
|
||||||
tb.Cleanup(func() {
|
tb.Cleanup(func() {
|
||||||
if tb.Failed() {
|
if tb.Failed() {
|
||||||
|
@ -705,6 +705,8 @@ func TestDiscokeyChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestActiveDiscovery(t *testing.T) {
|
func TestActiveDiscovery(t *testing.T) {
|
||||||
|
tstest.ResourceCheck(t)
|
||||||
|
|
||||||
t.Run("simple_internet", func(t *testing.T) {
|
t.Run("simple_internet", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
mstun := &natlab.Machine{Name: "stun"}
|
mstun := &natlab.Machine{Name: "stun"}
|
||||||
@ -900,7 +902,6 @@ func newPinger(t *testing.T, logf logger.Logf, src, dst *magicStack) (cleanup fu
|
|||||||
// get exercised.
|
// get exercised.
|
||||||
func testActiveDiscovery(t *testing.T, d *devices) {
|
func testActiveDiscovery(t *testing.T, d *devices) {
|
||||||
tstest.PanicOnLog()
|
tstest.PanicOnLog()
|
||||||
tstest.ResourceCheck(t)
|
|
||||||
|
|
||||||
tlogf, setT := makeNestable(t)
|
tlogf, setT := makeNestable(t)
|
||||||
setT(t)
|
setT(t)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user