tstest/tstest: add t.Parallel that can be disabled by TS_SERIAL_TESTS=true

Updates #9841

Change-Id: I1b8f4d6e34ac8540e3b0455a7c79bd400e2721b7
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/9835/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent 4dec0c6eb9
commit 6ca8650c7b

@ -75,7 +75,7 @@ func TestTUNMode(t *testing.T) {
if os.Getuid() != 0 { if os.Getuid() != 0 {
t.Skip("skipping when not root") t.Skip("skipping when not root")
} }
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
env.tunMode = true env.tunMode = true
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
@ -92,7 +92,7 @@ func TestTUNMode(t *testing.T) {
func TestOneNodeUpNoAuth(t *testing.T) { func TestOneNodeUpNoAuth(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
@ -110,7 +110,7 @@ func TestOneNodeUpNoAuth(t *testing.T) {
func TestOneNodeExpiredKey(t *testing.T) { func TestOneNodeExpiredKey(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
@ -147,7 +147,7 @@ func TestOneNodeExpiredKey(t *testing.T) {
func TestControlKnobs(t *testing.T) { func TestControlKnobs(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
@ -178,7 +178,7 @@ func TestControlKnobs(t *testing.T) {
func TestCollectPanic(t *testing.T) { func TestCollectPanic(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n := newTestNode(t, env) n := newTestNode(t, env)
@ -209,7 +209,7 @@ func TestCollectPanic(t *testing.T) {
func TestControlTimeLogLine(t *testing.T) { func TestControlTimeLogLine(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
env.LogCatcher.StoreRawJSON() env.LogCatcher.StoreRawJSON()
n := newTestNode(t, env) n := newTestNode(t, env)
@ -233,7 +233,7 @@ func TestControlTimeLogLine(t *testing.T) {
// test Issue 2321: Start with UpdatePrefs should save prefs to disk // test Issue 2321: Start with UpdatePrefs should save prefs to disk
func TestStateSavedOnStart(t *testing.T) { func TestStateSavedOnStart(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
@ -270,7 +270,7 @@ func TestStateSavedOnStart(t *testing.T) {
func TestOneNodeUpAuth(t *testing.T) { func TestOneNodeUpAuth(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t, configureControl(func(control *testcontrol.Server) { env := newTestEnv(t, configureControl(func(control *testcontrol.Server) {
control.RequireAuth = true control.RequireAuth = true
})) }))
@ -315,7 +315,7 @@ func TestOneNodeUpAuth(t *testing.T) {
func TestTwoNodes(t *testing.T) { func TestTwoNodes(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/3598") flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/3598")
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
// Create two nodes: // Create two nodes:
@ -365,7 +365,7 @@ func TestTwoNodes(t *testing.T) {
func TestIncrementalMapUpdatePeersRemoved(t *testing.T) { func TestIncrementalMapUpdatePeersRemoved(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/3598") flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/3598")
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
// Create one node: // Create one node:
@ -450,7 +450,7 @@ func TestIncrementalMapUpdatePeersRemoved(t *testing.T) {
func TestNodeAddressIPFields(t *testing.T) { func TestNodeAddressIPFields(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/7008") flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/7008")
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
d1 := n1.StartDaemon() d1 := n1.StartDaemon()
@ -477,7 +477,7 @@ func TestNodeAddressIPFields(t *testing.T) {
func TestAddPingRequest(t *testing.T) { func TestAddPingRequest(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
n1.StartDaemon() n1.StartDaemon()
@ -530,7 +530,7 @@ func TestAddPingRequest(t *testing.T) {
func TestC2NPingRequest(t *testing.T) { func TestC2NPingRequest(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
n1.StartDaemon() n1.StartDaemon()
@ -601,7 +601,7 @@ func TestC2NPingRequest(t *testing.T) {
// be connected to control. // be connected to control.
func TestNoControlConnWhenDown(t *testing.T) { func TestNoControlConnWhenDown(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
@ -643,7 +643,7 @@ func TestNoControlConnWhenDown(t *testing.T) {
// without the GUI to kick off a Start. // without the GUI to kick off a Start.
func TestOneNodeUpWindowsStyle(t *testing.T) { func TestOneNodeUpWindowsStyle(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
n1 := newTestNode(t, env) n1 := newTestNode(t, env)
n1.upFlagGOOS = "windows" n1.upFlagGOOS = "windows"
@ -662,7 +662,7 @@ func TestOneNodeUpWindowsStyle(t *testing.T) {
// tries to do bi-directional pings between them. // tries to do bi-directional pings between them.
func TestNATPing(t *testing.T) { func TestNATPing(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
for _, v6 := range []bool{false, true} { for _, v6 := range []bool{false, true} {
env := newTestEnv(t) env := newTestEnv(t)
registerNode := func() (*testNode, key.NodePublic) { registerNode := func() (*testNode, key.NodePublic) {
@ -790,7 +790,7 @@ func TestNATPing(t *testing.T) {
func TestLogoutRemovesAllPeers(t *testing.T) { func TestLogoutRemovesAllPeers(t *testing.T) {
tstest.Shard(t) tstest.Shard(t)
t.Parallel() tstest.Parallel(t)
env := newTestEnv(t) env := newTestEnv(t)
// Spin up some nodes. // Spin up some nodes.
nodes := make([]*testNode, 2) nodes := make([]*testNode, 2)

@ -13,6 +13,7 @@ import (
"testing" "testing"
"time" "time"
"tailscale.com/envknob"
"tailscale.com/logtail/backoff" "tailscale.com/logtail/backoff"
"tailscale.com/types/logger" "tailscale.com/types/logger"
) )
@ -74,3 +75,12 @@ func Shard(t testing.TB) {
t.Skipf("skipping shard %d/%d (process has TS_TEST_SHARD=%q)", shard, shards, e) t.Skipf("skipping shard %d/%d (process has TS_TEST_SHARD=%q)", shard, shards, e)
} }
} }
var serializeParallel = envknob.RegisterBool("TS_SERIAL_TESTS")
// Parallel calls t.Parallel, unless TS_SERIAL_TESTS is set true.
func Parallel(t *testing.T) {
if !serializeParallel() {
t.Parallel()
}
}

Loading…
Cancel
Save