Skip to content

Commit c9b31da

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

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
@@ -2170,7 +2170,7 @@ func RunLogicTest(t *testing.T, globs ...string) {
21702170
// the batch size is a global variable.
21712171
// TODO(jordan, radu): make sqlbase.kvBatchSize non-global to fix this.
21722172
if filepath.Base(path) != "select_index_span_ranges" {
2173-
t.Parallel()
2173+
t.Parallel() // SAFE FOR TESTING (this comments satisfies the linter)
21742174
}
21752175
}
21762176
lt := logicTest{

pkg/testutils/lint/lint_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,42 @@ func TestLint(t *testing.T) {
696696
}
697697
})
698698

699+
t.Run("TestTParallel", func(t *testing.T) {
700+
t.Parallel()
701+
cmd, stderr, filter, err := dirCmd(
702+
pkgDir,
703+
"git",
704+
"grep",
705+
"-nE",
706+
`\.Parallel\(\)`,
707+
"--",
708+
"*.go",
709+
":!testutils/lint/*.go",
710+
)
711+
if err != nil {
712+
t.Fatal(err)
713+
}
714+
715+
if err := cmd.Start(); err != nil {
716+
t.Fatal(err)
717+
}
718+
719+
if err := stream.ForEach(stream.Sequence(
720+
filter,
721+
stream.GrepNot(`// SAFE FOR TESTING`),
722+
), func(s string) {
723+
t.Errorf("\n%s <- forbidden, use a sync.WaitGroup instead (cf https://github.com/golang/go/issues/31651)", s)
724+
}); err != nil {
725+
t.Error(err)
726+
}
727+
728+
if err := cmd.Wait(); err != nil {
729+
if out := stderr.String(); len(out) > 0 {
730+
t.Fatalf("err=%s, stderr=%s", err, out)
731+
}
732+
}
733+
})
734+
699735
t.Run("TestProtoMarshal", func(t *testing.T) {
700736
t.Parallel()
701737
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)