MCPcopy Index your code
hub / github.com/coder/coder / useStandardTimeoutsAndDelaysInTests

Function useStandardTimeoutsAndDelaysInTests

scripts/rules.go:218–249  ·  view source on GitHub ↗

useStandardTimeoutsAndDelaysInTests ensures all tests use common constants for timeouts and delays in usual scenarios, this allows us to tweak them based on platform (important to avoid CI flakes). nolint:unused,deadcode,varnamelen

(m dsl.Matcher)

Source from the content-addressed store, hash-verified

216//
217//nolint:unused,deadcode,varnamelen
218func useStandardTimeoutsAndDelaysInTests(m dsl.Matcher) {
219 m.Import("github.com/stretchr/testify/require")
220 m.Import("github.com/stretchr/testify/assert")
221 m.Import("github.com/coder/coder/v2/testutil")
222
223 m.Match(`context.WithTimeout($ctx, $duration)`).
224 Where(m.File().Imports("testing") && !m.File().PkgPath.Matches("testutil$") && !m["duration"].Text.Matches("^testutil\\.")).
225 At(m["duration"]).
226 Report("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead.")
227
228 m.Match(`
229 $testify.$Eventually($t, func() bool {
230 $*_
231 }, $timeout, $interval, $*_)
232 `).
233 Where((m["testify"].Text == "require" || m["testify"].Text == "assert") &&
234 (m["Eventually"].Text == "Eventually" || m["Eventually"].Text == "Eventuallyf") &&
235 !m["timeout"].Text.Matches("^testutil\\.")).
236 At(m["timeout"]).
237 Report("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead.")
238
239 m.Match(`
240 $testify.$Eventually($t, func() bool {
241 $*_
242 }, $timeout, $interval, $*_)
243 `).
244 Where((m["testify"].Text == "require" || m["testify"].Text == "assert") &&
245 (m["Eventually"].Text == "Eventually" || m["Eventually"].Text == "Eventuallyf") &&
246 !m["interval"].Text.Matches("^testutil\\.")).
247 At(m["interval"]).
248 Report("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead.")
249}
250
251// HttpAPIErrorMessage intends to enforce constructing proper sentences as
252// error messages for the api. A proper sentence includes proper capitalization

Callers

nothing calls this directly

Calls 3

MatchMethod · 0.80
ReportMethod · 0.65
MatchesMethod · 0.45

Tested by

no test coverage detected