Run many tests in parallel
- Most tests under analytics_util and cmd touches global variables
so they weren't touched.
- cmdline had similar issues but with environment variables.
- cipd tests use Bootstrap() which is not concurrent safe.
- project tests use non hermetic temporary environment to run tests, and
furthermore can corrupt the current checkout commit history if run in
parallel.
Change-Id: I61fca6de7f820aba475a3806a30578a24404a7f8
diff --git a/cipd/cipd_test.go b/cipd/cipd_test.go
index 348a3a1..a59b78f 100644
--- a/cipd/cipd_test.go
+++ b/cipd/cipd_test.go
@@ -77,6 +77,7 @@
}
func TestCipdVersion(t *testing.T) {
+ t.Parallel()
// Assume cipd version is always a git commit hash for now
versionStr := string(cipdVersion)
if len(versionStr) != len("git_revision:00e2d8b49a4e7505d1c71f19d15c9e7c5b9245a5") ||
@@ -90,6 +91,7 @@
}
func TestFetchDigest(t *testing.T) {
+ t.Parallel()
tests := []string{
"linux-amd64",
"linux-arm64",
@@ -277,6 +279,7 @@
}
func TestExpand(t *testing.T) {
+ t.Parallel()
platforms := []Platform{
Platform{"linux", "amd64"},
Platform{"linux", "arm64"},
@@ -303,6 +306,7 @@
}
func TestMustExpand(t *testing.T) {
+ t.Parallel()
tests := map[string]bool{
"fuchsia/clang/${platform}": true,
"fuchsia/clang/${os}-${arch}": true,
@@ -317,6 +321,7 @@
}
func TestDecl(t *testing.T) {
+ t.Parallel()
platforms := []Platform{
Platform{"linux", "amd64"},
Platform{"linux", "arm64"},
diff --git a/color/color_test.go b/color/color_test.go
index 8e1e29a..cf4cdf0 100644
--- a/color/color_test.go
+++ b/color/color_test.go
@@ -6,6 +6,7 @@
)
func TestColors(t *testing.T) {
+ t.Parallel()
c := NewColor(ColorAlways)
colorFns := []Colorfn{c.Black, c.Red, c.Green, c.Yellow, c.Magenta, c.Cyan, c.White, c.DefaultColor}
colorCodes := []ColorCode{BlackFg, RedFg, GreenFg, YellowFg, MagentaFg, CyanFg, WhiteFg, DefaultFg}
@@ -43,6 +44,7 @@
}
func TestColorsDisabled(t *testing.T) {
+ t.Parallel()
c := NewColor(ColorNever)
colorFns := []Colorfn{c.Black, c.Red, c.Green, c.Yellow, c.Magenta, c.Cyan, c.White, c.DefaultColor}
diff --git a/envvar/envvar_test.go b/envvar/envvar_test.go
index 163cd34..9b659e6 100644
--- a/envvar/envvar_test.go
+++ b/envvar/envvar_test.go
@@ -11,6 +11,7 @@
)
func TestMapSliceFuncs(t *testing.T) {
+ t.Parallel()
tests := []struct {
FromMap, Map map[string]string
FromSlice, Slice []string
@@ -106,6 +107,7 @@
}
func TestSplitJoinKeyValue(t *testing.T) {
+ t.Parallel()
tests := []struct {
KV, Key, Value string
}{
@@ -136,6 +138,7 @@
}
func TestSplitJoinTokens(t *testing.T) {
+ t.Parallel()
tests := []struct {
Sep, FromValue, Value string
FromTokens, Tokens []string
@@ -162,6 +165,7 @@
}
func TestUniqueTokens(t *testing.T) {
+ t.Parallel()
tests := []struct {
Tokens, Want []string
}{
@@ -180,6 +184,7 @@
}
func TestFilterToken(t *testing.T) {
+ t.Parallel()
tests := []struct {
Tokens []string
Target string
@@ -210,6 +215,7 @@
}
func TestPrependUniqueToken(t *testing.T) {
+ t.Parallel()
tests := []struct {
Sep, Value, Token, Want string
}{
@@ -233,6 +239,7 @@
}
func TestAppendUniqueToken(t *testing.T) {
+ t.Parallel()
tests := []struct {
Sep, Value, Token, Want string
}{
@@ -255,6 +262,7 @@
}
func TestSortByKey(t *testing.T) {
+ t.Parallel()
tests := []struct {
In, Sorted []string
}{
@@ -424,6 +432,7 @@
var v123, vxyz, vfoo = "123", "x:y:z", "foo"
func TestZeroVars(t *testing.T) {
+ t.Parallel()
var vars Vars
if got, want := vars.Contains("A"), false; got != want {
t.Errorf(`Contains("A") got %v, want %v`, got, want)
@@ -466,6 +475,7 @@
}
func TestVarsFromMap(t *testing.T) {
+ t.Parallel()
vars := VarsFromMap(map[string]string{"A": "123", "B": "x:y:z"})
expectVarsAB(t, vars)
if got, want := vars.Deltas(), map[string]*string{}; !reflect.DeepEqual(got, want) {
@@ -492,6 +502,7 @@
}
func TestVarsFromSlice(t *testing.T) {
+ t.Parallel()
vars := VarsFromSlice([]string{"A=123", "B=x:y:z"})
expectVarsAB(t, vars)
if got, want := vars.Deltas(), map[string]*string{}; !reflect.DeepEqual(got, want) {
@@ -518,6 +529,7 @@
}
func TestVarsFromOS(t *testing.T) {
+ t.Parallel()
// Set an environment variable and make sure it shows up.
const testKey, testValue = "OS_ENV_TEST_KEY", "OS_ENV_TEST_VAL"
if err := os.Setenv(testKey, testValue); err != nil {
diff --git a/gerrit/gerrit_test.go b/gerrit/gerrit_test.go
index 76e8c06..68cbc1a 100644
--- a/gerrit/gerrit_test.go
+++ b/gerrit/gerrit_test.go
@@ -12,6 +12,7 @@
)
func TestParseQueryResults(t *testing.T) {
+ t.Parallel()
input := `)]}'
[
{
@@ -143,6 +144,7 @@
}
func TestParseMultiPartMatch(t *testing.T) {
+ t.Parallel()
type testCase struct {
str string
expectNoMatches bool
@@ -209,6 +211,7 @@
}
func TestParseValidGitCookieFile(t *testing.T) {
+ t.Parallel()
// Valid content.
gitCookieFileContent := `
vanadium.googlesource.com FALSE / TRUE 2147483647 o git-johndoe.example.com=12345
@@ -239,6 +242,7 @@
}
func TestParseInvalidGitCookieFile(t *testing.T) {
+ t.Parallel()
// Content with invalid entries which should be skipped.
gitCookieFileContentWithInvalidEntries := `
vanadium.googlesource.com FALSE / TRUE 2147483647 o git-johndoe.example.com
@@ -262,6 +266,7 @@
}
func TestParseValidNetRcFile(t *testing.T) {
+ t.Parallel()
// Valid content.
netrcFileContent := `
machine vanadium.googlesource.com login git-johndoe.example.com password 12345
@@ -287,6 +292,7 @@
}
func TestParseInvalidNetRcFile(t *testing.T) {
+ t.Parallel()
// Content with invalid entries which should be skipped.
netRcFileContentWithInvalidEntries := `
machine vanadium.googlesource.com login git-johndoe.example.com password
@@ -311,6 +317,7 @@
}
func TestParseRefString(t *testing.T) {
+ t.Parallel()
type testCase struct {
ref string
expectErr bool
@@ -359,6 +366,7 @@
}
func TestReference(t *testing.T) {
+ t.Parallel()
testOpts := CLOpts{
RemoteBranch: "master",
Labels: []string{"Commit-Queue+1"},
diff --git a/gerrit/multipart_test.go b/gerrit/multipart_test.go
index efb294e..c9edf9c 100644
--- a/gerrit/multipart_test.go
+++ b/gerrit/multipart_test.go
@@ -19,6 +19,7 @@
}
func TestMultiPartCLSet(t *testing.T) {
+ t.Parallel()
set := NewMultiPartCLSet()
checkMultiPartCLSet(t, -1, map[int]Change{}, set)
@@ -96,6 +97,7 @@
}
func TestNewOpenCLs(t *testing.T) {
+ t.Parallel()
nonMultiPartCLs := CLList{
GenCL(1010, 1, "release.go.core"),
GenCL(1020, 2, "release.go.tools"),
diff --git a/lookpath/lookpath_test.go b/lookpath/lookpath_test.go
index 73d3236..cbf981a 100644
--- a/lookpath/lookpath_test.go
+++ b/lookpath/lookpath_test.go
@@ -59,6 +59,7 @@
}
func TestLook(t *testing.T) {
+ t.Parallel()
tmpDir, cleanup := initTmpDir(t)
defer cleanup()
dirA, dirB := mkdir(t, tmpDir, "a"), mkdir(t, tmpDir, "b")
@@ -109,6 +110,7 @@
}
func TestLookPrefix(t *testing.T) {
+ t.Parallel()
tmpDir, cleanup := initTmpDir(t)
defer cleanup()
dirA, dirB := mkdir(t, tmpDir, "a"), mkdir(t, tmpDir, "b")
diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go
index 59efd63..550aa4c 100644
--- a/metadata/metadata_test.go
+++ b/metadata/metadata_test.go
@@ -90,6 +90,7 @@
}
func TestToMap(t *testing.T) {
+ t.Parallel()
for _, test := range allTests {
if got, want := test.MD.ToMap(), test.MD.entries; !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
@@ -98,6 +99,7 @@
}
func TestFromMap(t *testing.T) {
+ t.Parallel()
for _, test := range allTests {
if got, want := FromMap(test.MD.entries), test.MD; !reflect.DeepEqual(got, want) {
t.Errorf("got %#v, want %#v", got, want)
@@ -106,6 +108,7 @@
}
func TestToXML(t *testing.T) {
+ t.Parallel()
for _, test := range allTests {
if got, want := test.MD.ToXML(), test.XML; got != want {
t.Errorf("got %v, want %v", got, want)
@@ -114,6 +117,7 @@
}
func TestFromXML(t *testing.T) {
+ t.Parallel()
for _, test := range allTests {
got, err := FromXML([]byte(test.XML))
if err != nil {
@@ -131,6 +135,7 @@
}
func TestToBase64(t *testing.T) {
+ t.Parallel()
for _, test := range allTests {
got := test.MD.ToBase64()
found := false
@@ -147,6 +152,7 @@
}
func TestFromBase64(t *testing.T) {
+ t.Parallel()
for _, test := range allTests {
for _, b64 := range test.B64 {
got, err := FromBase64([]byte(b64))
@@ -166,6 +172,7 @@
}
func TestInsertLookup(t *testing.T) {
+ t.Parallel()
tests := []struct {
ID, Value, Old string
Map map[string]string
@@ -206,6 +213,7 @@
}
func TestLDFlag(t *testing.T) {
+ t.Parallel()
for _, test := range allTests {
got := LDFlag(test.MD)
found := false
@@ -224,6 +232,7 @@
// TestBuiltIn tests the package-level functions that operate on BuiltIn.
func TestBuiltIn(t *testing.T) {
+ t.Parallel()
const id, value1, value2 = "TestID", "testvalue1", "testvalue2"
if got, want := Lookup(id), ""; got != want {
t.Errorf("Lookup %s got %q, want %q", id, got, want)
@@ -257,6 +266,7 @@
// TestInitAndFlag builds a test binary with some metadata, and invokes the
// -metadata flag to make sure it dumps the expected metadata.
func TestInitAndFlag(t *testing.T) {
+ t.Parallel()
// Run the test binary.
const id, value = "zzzTestID", "abcdefg"
x := FromMap(map[string]string{id: value})
diff --git a/project/project_test.go b/project/project_test.go
index b172ebf..b19c293 100644
--- a/project/project_test.go
+++ b/project/project_test.go
@@ -2063,6 +2063,7 @@
}
func TestManifestToFromBytes(t *testing.T) {
+ t.Parallel()
tests := []struct {
Manifest project.Manifest
XML string
@@ -2164,6 +2165,7 @@
}
func TestProjectToFromFile(t *testing.T) {
+ t.Parallel()
jirix, cleanup := xtest.NewX(t)
defer cleanup()
@@ -2219,6 +2221,7 @@
}
func TestMarshalAndUnmarshalLockEntries(t *testing.T) {
+ t.Parallel()
projectLock0 := project.ProjectLock{"https://dart.googlesource.com/web_socket_channel.git", "dart", "1.0.9"}
pkgLock0 := project.PackageLock{
@@ -2278,6 +2281,7 @@
}
func TestGetPath(t *testing.T) {
+ t.Parallel()
testPkgs := []project.Package{
project.Package{Name: "test0", Version: "version", Path: "A/test0"},
project.Package{Name: "test1/${platform}", Version: "version", Path: ""},
@@ -2306,6 +2310,7 @@
}
func TestWritePackageFlags(t *testing.T) {
+ t.Parallel()
jirix, cleanup := xtest.NewX(t)
defer cleanup()
@@ -2350,6 +2355,7 @@
}
func TestWriteProjectFlags(t *testing.T) {
+ t.Parallel()
jirix, cleanup := xtest.NewX(t)
defer cleanup()
@@ -2382,6 +2388,7 @@
}
func TestPackageVersionTemplate(t *testing.T) {
+ t.Parallel()
jirix, cleanup := xtest.NewX(t)
defer cleanup()
@@ -2440,6 +2447,7 @@
}
func TestOptionalProjectsAndPackages(t *testing.T) {
+ t.Parallel()
fake, cleanup := jiritest.NewFakeJiriRoot(t)
defer cleanup()
@@ -2553,6 +2561,7 @@
}
func TestMultiplePackageVersions(t *testing.T) {
+ t.Parallel()
fake, cleanup := jiritest.NewFakeJiriRoot(t)
defer cleanup()
@@ -2639,6 +2648,7 @@
}
func TestHostnameAllowed(t *testing.T) {
+ t.Parallel()
tests := map[string]bool{
"*.google.com,fuchsia.google.com": true,
"*.google.com,fuchsia.dev.google.com": true,
@@ -2664,6 +2674,7 @@
}
func TestCheckProjectsHostnames(t *testing.T) {
+ t.Parallel()
allowList := []string{
"*.googlesource.com",
"fuchsia-internal",
diff --git a/simplemr/mr_test.go b/simplemr/mr_test.go
index a7a5c87..6ca1d25 100644
--- a/simplemr/mr_test.go
+++ b/simplemr/mr_test.go
@@ -69,6 +69,7 @@
}
func TestMR(t *testing.T) {
+ t.Parallel()
mrt := &simplemr.MR{}
in, out := newChans(10)
tc := &termCount{}
@@ -102,6 +103,7 @@
}
func TestTimeout(t *testing.T) {
+ t.Parallel()
in, out := newChans(1)
mrt := &simplemr.MR{Timeout: 100 * time.Millisecond}
identity := &simplemr.Identity{}
@@ -152,6 +154,7 @@
}
func TestOneMappers(t *testing.T) {
+ t.Parallel()
bufsize := 5
runtime := runMappers(t, bufsize, 1)
if got, want := runtime, time.Duration(int64(sleepTime)*int64(bufsize)); got < want {
@@ -186,6 +189,7 @@
}
func TestChainedMR(t *testing.T) {
+ t.Parallel()
chanSize := 5
in, middle, out := make(chan *simplemr.Record, chanSize), make(chan *simplemr.Record, chanSize), make(chan *simplemr.Record, chanSize)
mrt1 := &simplemr.MR{}
@@ -258,9 +262,11 @@
}
func TestCancelMappers(t *testing.T) {
+ t.Parallel()
testCancel(t, true)
}
func TestCancelReducers(t *testing.T) {
+ t.Parallel()
testCancel(t, false)
}
diff --git a/textutil/utf8_test.go b/textutil/utf8_test.go
index 64d6281..6148116 100644
--- a/textutil/utf8_test.go
+++ b/textutil/utf8_test.go
@@ -11,6 +11,7 @@
)
func TestUTF8ChunkDecoder(t *testing.T) {
+ t.Parallel()
r2 := "Δ"
r3 := "王"
r4 := "\U0001F680"
diff --git a/textutil/wrap_writer_test.go b/textutil/wrap_writer_test.go
index 986df11..d8ffd8e 100644
--- a/textutil/wrap_writer_test.go
+++ b/textutil/wrap_writer_test.go
@@ -21,6 +21,7 @@
)
func TestWrapWriter(t *testing.T) {
+ t.Parallel()
tests := []struct {
Width int
Indents [][]int
@@ -176,6 +177,7 @@
}
func TestWrapWriterForceVerbatim(t *testing.T) {
+ t.Parallel()
tests := []struct {
In string // See xlateIn for details on the format
Want string // See xlateIn for details on the format
diff --git a/textutil/writer_test.go b/textutil/writer_test.go
index dbb884d..4a409fa 100644
--- a/textutil/writer_test.go
+++ b/textutil/writer_test.go
@@ -14,6 +14,7 @@
)
func TestPrefixWriter(t *testing.T) {
+ t.Parallel()
tests := []struct {
Prefix string
Writes []string
@@ -73,6 +74,7 @@
}
func TestPrefixLineWriter(t *testing.T) {
+ t.Parallel()
tests := []struct {
Prefix string
Writes []string
@@ -180,6 +182,7 @@
}
func TestPrefixLineWriter_Flush(t *testing.T) {
+ t.Parallel()
fake := &fakeWriteFlusher{}
w := PrefixLineWriter(fake, "prefix")
if err := w.Flush(); err != nil {
@@ -191,6 +194,7 @@
}
func TestPrefixLineWriter_FlushError(t *testing.T) {
+ t.Parallel()
fake := &fakeWriteFlusher{flushErr: err1}
w := PrefixLineWriter(fake, "prefix")
if err := w.Flush(); err != err1 {
@@ -202,6 +206,7 @@
}
func TestPrefixLineWriter_WriteFlush(t *testing.T) {
+ t.Parallel()
fake := &fakeWriteFlusher{}
w := PrefixLineWriter(fake, "prefix")
if n, err := w.Write([]byte("abc")); n != 3 || err != nil {
@@ -216,6 +221,7 @@
}
func TestPrefixLineWriter_WriteFlushError(t *testing.T) {
+ t.Parallel()
fake := &fakeWriteFlusher{flushErr: err1}
w := PrefixLineWriter(fake, "prefix")
if n, err := w.Write([]byte("abc")); n != 3 || err != nil {
@@ -230,6 +236,7 @@
}
func TestPrefixLineWriter_WriteErrorFlush(t *testing.T) {
+ t.Parallel()
fake := &fakeWriteFlusher{writeErr: err1}
w := PrefixLineWriter(fake, "prefix")
if n, err := w.Write([]byte("abc")); n != 3 || err != nil {
@@ -244,6 +251,7 @@
}
func TestPrefixLineWriter_WriteErrorFlushError(t *testing.T) {
+ t.Parallel()
fake := &fakeWriteFlusher{writeErr: err1, flushErr: err2}
w := PrefixLineWriter(fake, "prefix")
if n, err := w.Write([]byte("abc")); n != 3 || err != nil {
@@ -258,6 +266,7 @@
}
func TestPrefixLineWriter_EOLWriteErrorFlushError(t *testing.T) {
+ t.Parallel()
fake := &fakeWriteFlusher{writeErr: err1, flushErr: err2}
w := PrefixLineWriter(fake, "prefix")
if n, err := w.Write([]byte("ab\n")); n != 3 || err != err1 {
@@ -272,6 +281,7 @@
}
func TestByteReplaceWriter(t *testing.T) {
+ t.Parallel()
tests := []struct {
Old byte
New string
diff --git a/timing/timer_test.go b/timing/timer_test.go
index bfc6991..0982dc3 100644
--- a/timing/timer_test.go
+++ b/timing/timer_test.go
@@ -83,6 +83,7 @@
}
func TestTimer(t *testing.T) {
+ t.Parallel()
tests := []struct {
ops []op
intervals []Interval
@@ -430,6 +431,7 @@
// TestIntervalPrinterCornerCases tests corner cases for the printer. These are
// all cases where only a subset of the full Timer intervals is printed.
func TestIntervalPrinterCornerCases(t *testing.T) {
+ t.Parallel()
tests := []struct {
intervals []Interval
str string
diff --git a/update_test.go b/update_test.go
index 2adf35c..d0ad55b 100644
--- a/update_test.go
+++ b/update_test.go
@@ -15,6 +15,7 @@
)
func TestGetCurrentCommit(t *testing.T) {
+ t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `)]}'
@@ -36,6 +37,7 @@
}
func TestHasPrebuilt(t *testing.T) {
+ t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
@@ -48,6 +50,7 @@
}
func TestDoesNotHavePrebuilt(t *testing.T) {
+ t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
@@ -60,6 +63,7 @@
}
func TestDownloadBinary(t *testing.T) {
+ t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
b := bytes.NewBuffer([]byte("jiri"))
@@ -77,6 +81,7 @@
}
func TestUpdateExecutable(t *testing.T) {
+ t.Parallel()
content := []byte("old")
f, err := ioutil.TempFile("", "jiri")
diff --git a/x_test.go b/x_test.go
index d119fae..ceb9ba7 100644
--- a/x_test.go
+++ b/x_test.go
@@ -15,6 +15,7 @@
// -root flag as a path, evaluates any symlinks the path might contain, and
// returns the result.
func TestFindRootEnvSymlink(t *testing.T) {
+ t.Parallel()
// Create a temporary directory.
tmpDir, err := ioutil.TempDir("", "")
if err != nil {