mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore: add testutil.Eventually and friends (#3389)
This PR adds a `testutil` function aimed to replace `require.Eventually`.
Before:
```go
require.Eventually(t, func() bool { ... }, testutil.WaitShort, testutil.IntervalFast)
```
After:
```go
require.True(t, testutil.EventuallyShort(t, func(ctx context.Context) bool { ... }))
// or the full incantation if you need more control
ctx, cancel := context.WithTimeout(ctx.Background(), testutil.WaitLong)
require.True(t, testutil.Eventually(t, ctx, func(ctx context.Context) bool { ... }, testutil.IntervalSlow))
```
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
This commit is contained in:
+1
-1
@@ -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.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user