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

ci: improve 'tfail in goroutine' ruleguard rule#19682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 1 commit intomainfromethan/improve-tfail-in-goroutine
Sep 4, 2025

Conversation

ethanndickson
Copy link
Member

@ethanndicksonethanndickson commentedSep 3, 2025
edited
Loading

This PR improves the ruleguard rule for detectingt.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 arequire in anEventually.

@ethanndicksonGraphite App
Copy link
MemberAuthor

This stack of pull requests is managed byGraphite. Learn more aboutstacking.

Comment on lines 183 to -189
go func($*_){
$*_
$require.$_($*_)
require.$_($*_)
$*_
}($*_)`).
At(m["require"]).
Where(m["require"].Text=="require").
Copy link
MemberAuthor

@ethanndicksonethanndicksonSep 3, 2025
edited
Loading

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 therequire.* came after some otherselector.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 isrequires.

Comment on lines 199 to 208
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)")
}
Copy link
MemberAuthor

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 othert.* function that's called before thet.Fail/whatever the rule won't fire. It's not perfect, but it's probably good enough.

@ethanndicksonethanndicksonforce-pushed theethan/improve-tfail-in-goroutine branch from7eba8dd to10d0f7fCompareSeptember 3, 2025 05:31
@ethanndicksonethanndickson marked this pull request as ready for reviewSeptember 3, 2025 05:32
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

Thanks for improving this! Ruleguard DSL is tricky at the best of times.

@ethanndicksonethanndickson merged commit50704a5 intomainSep 4, 2025
29 checks passed
@ethanndicksonethanndickson deleted the ethan/improve-tfail-in-goroutine branchSeptember 4, 2025 04:28
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsSep 4, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@ethanndicksonethanndickson

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@ethanndickson@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp