Skip to content

Commit 6f30625

Browse files
committed
lint: add a linter to forbid uses of t.Parallel()
This suggests using `sync.WaitGroup` instead. Release note: None
1 parent 9c4fcee commit 6f30625

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

pkg/sql/logictest/logic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ func RunLogicTest(t *testing.T, globs ...string) {
21452145
// the batch size is a global variable.
21462146
// TODO(jordan, radu): make sqlbase.kvBatchSize non-global to fix this.
21472147
if filepath.Base(path) != "select_index_span_ranges" {
2148-
t.Parallel()
2148+
t.Parallel() // SAFE FOR TESTING (this comments satisfies the linter)
21492149
}
21502150
}
21512151
lt := logicTest{

pkg/testutils/lint/lint_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,42 @@ func TestLint(t *testing.T) {
748748
}
749749
})
750750

751+
t.Run("TestTParallel", func(t *testing.T) {
752+
t.Parallel()
753+
cmd, stderr, filter, err := dirCmd(
754+
pkgDir,
755+
"git",
756+
"grep",
757+
"-nE",
758+
`\.Parallel\(\)`,
759+
"--",
760+
"*.go",
761+
":!testutils/lint/*.go",
762+
)
763+
if err != nil {
764+
t.Fatal(err)
765+
}
766+
767+
if err := cmd.Start(); err != nil {
768+
t.Fatal(err)
769+
}
770+
771+
if err := stream.ForEach(stream.Sequence(
772+
filter,
773+
stream.GrepNot(`// SAFE FOR TESTING`),
774+
), func(s string) {
775+
t.Errorf("\n%s <- forbidden, use a sync.WaitGroup instead (cf https://github.com/golang/go/issues/31651)", s)
776+
}); err != nil {
777+
t.Error(err)
778+
}
779+
780+
if err := cmd.Wait(); err != nil {
781+
if out := stderr.String(); len(out) > 0 {
782+
t.Fatalf("err=%s, stderr=%s", err, out)
783+
}
784+
}
785+
})
786+
751787
t.Run("TestProtoMarshal", func(t *testing.T) {
752788
t.Parallel()
753789
cmd, stderr, filter, err := dirCmd(

pkg/util/fast_int_map_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestFastIntMap(t *testing.T) {
3333
}
3434
for _, tc := range cases {
3535
t.Run(fmt.Sprintf("%d-%d", tc.keyRange, tc.valRange), func(t *testing.T) {
36-
t.Parallel()
36+
t.Parallel() // SAFE FOR TESTING (this comment is for the linter)
3737
rng, _ := randutil.NewPseudoRand()
3838
var fm FastIntMap
3939
m := make(map[int]int)

pkg/util/fast_int_set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestFastIntSet(t *testing.T) {
2626
for _, mVal := range []int{1, 8, 30, smallCutoff, 2 * smallCutoff, 4 * smallCutoff} {
2727
m := mVal
2828
t.Run(fmt.Sprintf("%d", m), func(t *testing.T) {
29-
t.Parallel()
29+
t.Parallel() // SAFE FOR TESTING (this comment is for the linter)
3030
rng, _ := randutil.NewPseudoRand()
3131
in := make([]bool, m)
3232
forEachRes := make([]bool, m)

0 commit comments

Comments
 (0)