Skip to content

chore: add testutil.Eventually and friends #3389

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix ruleguard linter
  • Loading branch information
johnstcn committed Aug 5, 2022
commit 32b578ec71a7ffed39bae581aedf06dbcecd5338
2 changes: 1 addition & 1 deletion scripts/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func useStandardTimeoutsAndDelaysInTests(m dsl.Matcher) {
m.Import("github.com/coder/coder/testutil")

m.Match(`context.WithTimeout($ctx, $duration)`).
Where(m.File().Imports("testing") && !m["duration"].Text.Matches("^testutil\\.")).
Where(m.File().Imports("testing") && !m.File().PkgPath.Matches("testutil$") && !m["duration"].Text.Matches("^testutil\\.")).
At(m["duration"]).
Report("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead.")

Expand Down
3 changes: 0 additions & 3 deletions testutil/eventually.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func Eventually(ctx context.Context, t testing.TB, condition func() bool, tick t
// EventuallyShort is a convenience function that runs Eventually with
// IntervalFast and times out after WaitShort.
func EventuallyShort(t testing.TB, condition func() bool) bool {
//nolint: gocritic
ctx, cancel := context.WithTimeout(context.Background(), WaitShort)
defer cancel()
return Eventually(ctx, t, condition, IntervalFast)
Expand All @@ -48,7 +47,6 @@ func EventuallyShort(t testing.TB, condition func() bool) bool {
// EventuallyMedium is a convenience function that runs Eventually with
// IntervalMedium and times out after WaitMedium.
func EventuallyMedium(t testing.TB, condition func() bool) bool {
//nolint: gocritic
ctx, cancel := context.WithTimeout(context.Background(), WaitMedium)
defer cancel()
return Eventually(ctx, t, condition, IntervalMedium)
Expand All @@ -57,7 +55,6 @@ func EventuallyMedium(t testing.TB, condition func() bool) bool {
// EventuallyLong is a convenience function that runs Eventually with
// IntervalSlow and times out after WaitLong.
func EventuallyLong(t testing.TB, condition func() bool) bool {
//nolint: gocritic
ctx, cancel := context.WithTimeout(context.Background(), WaitLong)
defer cancel()
return Eventually(ctx, t, condition, IntervalSlow)
Expand Down