util/testenv: add func to report whether a testing.TB is in parallel mode

For future in-memory network changes (#15558) to be able to be
stricter and do automatic leak detection when it's safe to do so, in
non-parallel tests.

Updates tailscale/corp#27636

Change-Id: I50f03b16a3f92ce61a7ed88264b49d8c6628f638
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2025-04-06 13:27:10 -07:00
committed by Brad Fitzpatrick
parent 603a1d3830
commit 6d117d64a2
2 changed files with 52 additions and 0 deletions

View File

@@ -16,3 +16,16 @@ func TestDeps(t *testing.T) {
},
}.Check(t)
}
func TestInParallelTestTrue(t *testing.T) {
t.Parallel()
if !InParallelTest(t) {
t.Fatal("InParallelTest should return true once t.Parallel has been called")
}
}
func TestInParallelTestFalse(t *testing.T) {
if InParallelTest(t) {
t.Fatal("InParallelTest should return false before t.Parallel has been called")
}
}