Make lots of tests run in parallel
Putting t.Parallel() in each test makes them run in parallel.
Additional t.Parallel() could be added to each subtest, although
that requires making a local copy of the loop variable for
table driven tests.
Test: m checkbuild
Change-Id: I5d9869ead441093f4d7c5757f2447385333a95a4
diff --git a/ui/build/cleanbuild_test.go b/ui/build/cleanbuild_test.go
index 89f4ad9..be60362 100644
--- a/ui/build/cleanbuild_test.go
+++ b/ui/build/cleanbuild_test.go
@@ -27,6 +27,7 @@
)
func TestCleanOldFiles(t *testing.T) {
+ t.Parallel()
dir, err := ioutil.TempDir("", "testcleanoldfiles")
if err != nil {
t.Fatal(err)
diff --git a/ui/build/config_test.go b/ui/build/config_test.go
index 7b14c47..35c6ed4 100644
--- a/ui/build/config_test.go
+++ b/ui/build/config_test.go
@@ -39,6 +39,7 @@
}
func TestConfigParseArgsJK(t *testing.T) {
+ t.Parallel()
ctx := testContext()
testCases := []struct {
@@ -111,6 +112,7 @@
}
func TestConfigParseArgsVars(t *testing.T) {
+ t.Parallel()
ctx := testContext()
testCases := []struct {
@@ -638,6 +640,7 @@
}
func TestConfigSplitArgs(t *testing.T) {
+ t.Parallel()
tests := []struct {
// ********* Setup *********
// Test description.
diff --git a/ui/build/environment_test.go b/ui/build/environment_test.go
index 37f500f..d8f83f4 100644
--- a/ui/build/environment_test.go
+++ b/ui/build/environment_test.go
@@ -21,6 +21,7 @@
)
func TestEnvUnset(t *testing.T) {
+ t.Parallel()
initial := &Environment{"TEST=1", "TEST2=0"}
initial.Unset("TEST")
got := initial.Environ()
@@ -30,6 +31,7 @@
}
func TestEnvUnsetMissing(t *testing.T) {
+ t.Parallel()
initial := &Environment{"TEST2=0"}
initial.Unset("TEST")
got := initial.Environ()
@@ -39,6 +41,7 @@
}
func TestEnvSet(t *testing.T) {
+ t.Parallel()
initial := &Environment{}
initial.Set("TEST", "0")
got := initial.Environ()
@@ -48,6 +51,7 @@
}
func TestEnvSetDup(t *testing.T) {
+ t.Parallel()
initial := &Environment{"TEST=1"}
initial.Set("TEST", "0")
got := initial.Environ()
@@ -57,6 +61,7 @@
}
func TestEnvAllow(t *testing.T) {
+ t.Parallel()
initial := &Environment{"TEST=1", "TEST2=0", "TEST3=2"}
initial.Allow("TEST3", "TEST")
got := initial.Environ()
@@ -73,6 +78,7 @@
`
func TestEnvAppendFromKati(t *testing.T) {
+ t.Parallel()
initial := &Environment{"CLANG=/usr/bin/clang", "TEST=0"}
err := initial.appendFromKati(strings.NewReader(testKatiEnvFileContents))
if err != nil {
diff --git a/ui/build/paths/logs_test.go b/ui/build/paths/logs_test.go
index 3b1005f..d5921a8 100644
--- a/ui/build/paths/logs_test.go
+++ b/ui/build/paths/logs_test.go
@@ -26,6 +26,7 @@
)
func TestSendLog(t *testing.T) {
+ t.Parallel()
t.Run("Short name", func(t *testing.T) {
d, err := ioutil.TempDir("", "s")
if err != nil {
@@ -105,6 +106,7 @@
}
func TestSendLogError(t *testing.T) {
+ t.Parallel()
d, err := ioutil.TempDir("", "log_socket")
if err != nil {
t.Fatal(err)
diff --git a/ui/build/proc_sync_test.go b/ui/build/proc_sync_test.go
index 857bea3..1b52fce 100644
--- a/ui/build/proc_sync_test.go
+++ b/ui/build/proc_sync_test.go
@@ -108,6 +108,7 @@
// simple test
func TestGetLock(t *testing.T) {
+ t.Parallel()
lockfile := lockOrFail(t)
defer removeTestLock(lockfile)
}
@@ -119,6 +120,7 @@
var busyStatus = 2
func TestTrylock(t *testing.T) {
+ t.Parallel()
lockpath := os.Getenv(lockPathVariable)
if len(lockpath) < 1 {
checkTrylockMainProcess(t)
@@ -204,6 +206,7 @@
}
func TestLockFirstTrySucceeds(t *testing.T) {
+ t.Parallel()
noopLogger := logger.New(ioutil.Discard)
lock := testLockCountingTo(0)
waiter := newCountWaiter(0)
@@ -216,6 +219,7 @@
}
}
func TestLockThirdTrySucceeds(t *testing.T) {
+ t.Parallel()
noopLogger := logger.New(ioutil.Discard)
lock := testLockCountingTo(2)
waiter := newCountWaiter(2)
@@ -228,6 +232,7 @@
}
}
func TestLockTimedOut(t *testing.T) {
+ t.Parallel()
noopLogger := logger.New(ioutil.Discard)
lock := testLockCountingTo(3)
waiter := newCountWaiter(2)
diff --git a/ui/build/rbe_test.go b/ui/build/rbe_test.go
index 8ff96bc..fa371bb 100644
--- a/ui/build/rbe_test.go
+++ b/ui/build/rbe_test.go
@@ -26,6 +26,7 @@
)
func TestDumpRBEMetrics(t *testing.T) {
+ t.Parallel()
ctx := testContext()
tests := []struct {
description string
@@ -81,6 +82,7 @@
}
func TestDumpRBEMetricsErrors(t *testing.T) {
+ t.Parallel()
ctx := testContext()
tests := []struct {
description string
diff --git a/ui/build/util_test.go b/ui/build/util_test.go
index b22e997..a06c3e9 100644
--- a/ui/build/util_test.go
+++ b/ui/build/util_test.go
@@ -25,6 +25,7 @@
)
func TestEnsureEmptyDirs(t *testing.T) {
+ t.Parallel()
ctx := testContext()
defer logger.Recover(func(err error) {
t.Error(err)
@@ -52,6 +53,7 @@
}
func TestCopyFile(t *testing.T) {
+ t.Parallel()
tmpDir, err := ioutil.TempDir("", "test_copy_file")
if err != nil {
t.Fatalf("failed to create temporary directory to hold test text files: %v", err)
@@ -86,6 +88,7 @@
}
func TestCopyFileErrors(t *testing.T) {
+ t.Parallel()
tmpDir, err := ioutil.TempDir("", "test_copy_file_errors")
if err != nil {
t.Fatalf("failed to create temporary directory to hold test text files: %v", err)
diff --git a/ui/logger/logger_test.go b/ui/logger/logger_test.go
index 044e6f0..7b3791c 100644
--- a/ui/logger/logger_test.go
+++ b/ui/logger/logger_test.go
@@ -29,6 +29,7 @@
)
func TestCreateFileWithRotation(t *testing.T) {
+ t.Parallel()
dir, err := ioutil.TempDir("", "test-rotation")
if err != nil {
t.Fatalf("Failed to get TempDir: %v", err)
@@ -96,6 +97,7 @@
}
func TestPanic(t *testing.T) {
+ t.Parallel()
if os.Getenv("ACTUALLY_PANIC") == "1" {
panicValue := "foo"
log := New(&bytes.Buffer{})
@@ -128,6 +130,7 @@
}
func TestFatal(t *testing.T) {
+ t.Parallel()
if os.Getenv("ACTUALLY_FATAL") == "1" {
log := New(&bytes.Buffer{})
defer func() {
@@ -150,6 +153,7 @@
}
func TestNonFatal(t *testing.T) {
+ t.Parallel()
if os.Getenv("ACTUAL_TEST") == "1" {
log := New(&bytes.Buffer{})
defer log.Cleanup()
@@ -166,6 +170,7 @@
}
func TestRecoverFatal(t *testing.T) {
+ t.Parallel()
log := New(&bytes.Buffer{})
defer func() {
if p := recover(); p != nil {
@@ -182,6 +187,7 @@
}
func TestRecoverNonFatal(t *testing.T) {
+ t.Parallel()
log := New(&bytes.Buffer{})
defer func() {
if p := recover(); p == nil {
@@ -198,6 +204,7 @@
}
func TestRuntimePanic(t *testing.T) {
+ t.Parallel()
defer func() {
if p := recover(); p == nil {
t.Errorf("Panic not thrown")
diff --git a/ui/metrics/time_test.go b/ui/metrics/time_test.go
index d73080a..16d6a20 100644
--- a/ui/metrics/time_test.go
+++ b/ui/metrics/time_test.go
@@ -22,6 +22,7 @@
)
func TestEnd(t *testing.T) {
+ t.Parallel()
startTime := time.Date(2020, time.July, 13, 13, 0, 0, 0, time.UTC)
dur := time.Nanosecond * 10
initialNow := _now
diff --git a/ui/status/critical_path_test.go b/ui/status/critical_path_test.go
index 965e0ad..e44298b 100644
--- a/ui/status/critical_path_test.go
+++ b/ui/status/critical_path_test.go
@@ -51,6 +51,7 @@
}
func TestCriticalPath(t *testing.T) {
+ t.Parallel()
tests := []struct {
name string
msgs func(*testCriticalPath)
diff --git a/ui/status/kati_test.go b/ui/status/kati_test.go
index f2cb813..24a38b3 100644
--- a/ui/status/kati_test.go
+++ b/ui/status/kati_test.go
@@ -43,6 +43,7 @@
func (l *lastOutput) Flush() {}
func TestKatiNormalCase(t *testing.T) {
+ t.Parallel()
status := &Status{}
output := &lastOutput{}
status.AddOutput(output)
@@ -110,6 +111,7 @@
}
func TestKatiExtraIncludes(t *testing.T) {
+ t.Parallel()
status := &Status{}
output := &lastOutput{}
status.AddOutput(output)
@@ -156,6 +158,7 @@
}
func TestKatiFailOnError(t *testing.T) {
+ t.Parallel()
status := &Status{}
output := &lastOutput{}
status.AddOutput(output)
diff --git a/ui/status/ninja_test.go b/ui/status/ninja_test.go
index c400c97..232be55 100644
--- a/ui/status/ninja_test.go
+++ b/ui/status/ninja_test.go
@@ -26,6 +26,7 @@
// Tests that closing the ninja reader when nothing has opened the other end of the fifo is fast.
func TestNinjaReader_Close(t *testing.T) {
+ t.Parallel()
tempDir, err := ioutil.TempDir("", "ninja_test")
if err != nil {
t.Fatal(err)
diff --git a/ui/status/status_test.go b/ui/status/status_test.go
index 9494582..2a90c7b 100644
--- a/ui/status/status_test.go
+++ b/ui/status/status_test.go
@@ -53,6 +53,7 @@
}
func TestBasicUse(t *testing.T) {
+ t.Parallel()
status := &Status{}
counts := &counterOutput{}
status.AddOutput(counts)
@@ -101,6 +102,7 @@
// For when a tool claims to have 2 actions, but finishes after one.
func TestFinishEarly(t *testing.T) {
+ t.Parallel()
status := &Status{}
counts := &counterOutput{}
status.AddOutput(counts)
@@ -129,6 +131,7 @@
// For when a tool claims to have 1 action, but starts two.
func TestExtraActions(t *testing.T) {
+ t.Parallel()
status := &Status{}
counts := &counterOutput{}
status.AddOutput(counts)
@@ -149,6 +152,7 @@
// When a tool calls Finish() with a running Action
func TestRunningWhenFinished(t *testing.T) {
+ t.Parallel()
status := &Status{}
counts := &counterOutput{}
status.AddOutput(counts)
diff --git a/ui/terminal/status_test.go b/ui/terminal/status_test.go
index aa69dff..da10912 100644
--- a/ui/terminal/status_test.go
+++ b/ui/terminal/status_test.go
@@ -25,6 +25,7 @@
)
func TestStatusOutput(t *testing.T) {
+ t.Parallel()
tests := []struct {
name string
calls func(stat status.StatusOutput)
@@ -266,6 +267,7 @@
}
func TestSmartStatusOutputWidthChange(t *testing.T) {
+ t.Parallel()
os.Setenv(tableHeightEnVar, "")
smart := &fakeSmartTerminal{termWidth: 40}
diff --git a/ui/terminal/util_test.go b/ui/terminal/util_test.go
index 82bde7c..b01b133 100644
--- a/ui/terminal/util_test.go
+++ b/ui/terminal/util_test.go
@@ -19,6 +19,7 @@
)
func TestStripAnsiEscapes(t *testing.T) {
+ t.Parallel()
testcases := []struct {
input string
output string