Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion coderd/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/archive"
Expand Down Expand Up @@ -88,7 +89,7 @@ func TestPostFiles(t *testing.T) {
data := make([]byte, 1024)
_, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
end.Done()
require.NoError(t, err)
assert.NoError(t, err)
}()
}
wg.Done()
Expand Down
4 changes: 2 additions & 2 deletions enterprise/tailnet/pgcoord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ func TestPGCoordinatorSingle_SendsHeartbeats(t *testing.T) {
if len(heartbeats) < 2 {
return false
}
require.Greater(t, heartbeats[0].Sub(start), time.Duration(0))
require.Greater(t, heartbeats[1].Sub(start), time.Duration(0))
assert.Greater(t, heartbeats[0].Sub(start), time.Duration(0))
assert.Greater(t, heartbeats[1].Sub(start), time.Duration(0))
return assert.Greater(t, heartbeats[1].Sub(heartbeats[0]), tailnet.HeartbeatPeriod*3/4)
}, testutil.WaitMedium, testutil.IntervalMedium)
}
Expand Down
2 changes: 1 addition & 1 deletion scaletest/createworkspaces/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func Test_Runner(t *testing.T) {
err := runner.Run(runnerCtx, "1", logs)
logsStr := logs.String()
t.Log("Runner logs:\n\n" + logsStr)
require.ErrorIs(t, err, context.Canceled)
assert.ErrorIs(t, err, context.Canceled)
close(done)
}()

Expand Down
12 changes: 4 additions & 8 deletions scripts/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,32 +182,28 @@ func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) {
m.Match(`
go func($*_){
$*_
$require.$_($*_)
require.$_($*_)
$*_
}($*_)`).
At(m["require"]).
Where(m["require"].Text == "require").
Comment on lines 183 to -189
Copy link
Member Author

@ethanndickson ethanndickson Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prior version would only match on the first line in the goroutine of the form <A>.<B>(<C>), meaning the rule wouldn't fire a violation if the require.* came after some other selector.Func. Ruleguard's pretty limited, and neither I nor Blink could find a way to make the matching not greedy.

To fix, we're just going to only match on lines where the selector is requires.

Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")

// require.Eventually runs the function in a goroutine.
m.Match(`
require.Eventually(t, func() bool {
$*_
$require.$_($*_)
require.$_($*_)
$*_
}, $*_)`).
At(m["require"]).
Where(m["require"].Text == "require").
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")

m.Match(`
go func($*_){
$*_
$t.$fail($*_)
t.$fail($*_)
$*_
}($*_)`).
At(m["fail"]).
Where(m["t"].Type.Implements("testing.TB") && m["fail"].Text.Matches("^(FailNow|Fatal|Fatalf)$")).
Where(m["fail"].Text.Matches("^(FailNow|Fatal|Fatalf)$")).
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
}
Comment on lines 199 to 208
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We apply the same idea here, but with a caveat that if there's some other t.* function that's called before the t.Fail/whatever the rule won't fire. It's not perfect, but it's probably good enough.


Expand Down
Loading