Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50704a5

Browse files
ci: improve 'tfail in goroutine' ruleguard rule (#19682)
This PR improves the ruleguard rule for detecting `t.Fail` calls in goroutines. It picks up additional violations, of which are fixed in this PR.See self-review for details.The motivation for fixing this comes from a flake I fixed in#19599, where tests would fail from a `require` in an `Eventually`.
1 parent1b4ce09 commit50704a5

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

‎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
iflen(heartbeats)<2 {
410410
returnfalse
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
returnassert.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)

[8]ページ先頭

©2009-2025 Movatter.jp