Skip to content

Commit 7eba8dd

Browse files
committed
ci: improve 'tfail in goroutine' ruleguard rule
1 parent 6606d8b commit 7eba8dd

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

coderd/files/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestConcurrentFetch(t *testing.T) {
114114
hold.Done()
115115
hold.Wait()
116116
_, err := cache.Acquire(ctx, dbM, fileID)
117-
require.NoError(t, err)
117+
assert.NoError(t, err)
118118
}()
119119
}
120120

coderd/files_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/google/uuid"
12+
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314

1415
"github.com/coder/coder/v2/archive"
@@ -88,7 +89,7 @@ func TestPostFiles(t *testing.T) {
8889
data := make([]byte, 1024)
8990
_, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
9091
end.Done()
91-
require.NoError(t, err)
92+
assert.NoError(t, err)
9293
}()
9394
}
9495
wg.Done()

enterprise/tailnet/pgcoord_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ func TestPGCoordinatorSingle_SendsHeartbeats(t *testing.T) {
409409
if len(heartbeats) < 2 {
410410
return false
411411
}
412-
require.Greater(t, heartbeats[0].Sub(start), time.Duration(0))
413-
require.Greater(t, heartbeats[1].Sub(start), time.Duration(0))
412+
assert.Greater(t, heartbeats[0].Sub(start), time.Duration(0))
413+
assert.Greater(t, heartbeats[1].Sub(start), time.Duration(0))
414414
return assert.Greater(t, heartbeats[1].Sub(heartbeats[0]), tailnet.HeartbeatPeriod*3/4)
415415
}, testutil.WaitMedium, testutil.IntervalMedium)
416416
}

scaletest/createworkspaces/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func Test_Runner(t *testing.T) {
257257
err := runner.Run(runnerCtx, "1", logs)
258258
logsStr := logs.String()
259259
t.Log("Runner logs:\n\n" + logsStr)
260-
require.ErrorIs(t, err, context.Canceled)
260+
assert.ErrorIs(t, err, context.Canceled)
261261
close(done)
262262
}()
263263

scripts/rules.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,32 +182,28 @@ func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) {
182182
m.Match(`
183183
go func($*_){
184184
$*_
185-
$require.$_($*_)
185+
require.$_($*_)
186186
$*_
187187
}($*_)`).
188-
At(m["require"]).
189-
Where(m["require"].Text == "require").
190188
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
191189

192190
// require.Eventually runs the function in a goroutine.
193191
m.Match(`
194192
require.Eventually(t, func() bool {
195193
$*_
196-
$require.$_($*_)
194+
require.$_($*_)
197195
$*_
198196
}, $*_)`).
199-
At(m["require"]).
200-
Where(m["require"].Text == "require").
201197
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
202198

203199
m.Match(`
204200
go func($*_){
205201
$*_
206-
$t.$fail($*_)
202+
t.$fail($*_)
207203
$*_
208204
}($*_)`).
209205
At(m["fail"]).
210-
Where(m["t"].Type.Implements("testing.TB") && m["fail"].Text.Matches("^(FailNow|Fatal|Fatalf)$")).
206+
Where(m["fail"].Text.Matches("^(FailNow|Fatal|Fatalf)$")).
211207
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
212208
}
213209

0 commit comments

Comments
 (0)