mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
chore: Use standardized test timeouts and delays (#3291)
This commit is contained in:
committed by
GitHub
parent
3d0febdd90
commit
4730c589fe
@ -81,6 +81,43 @@ func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) {
|
||||
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
|
||||
}
|
||||
|
||||
// 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
|
||||
func useStandardTimeoutsAndDelaysInTests(m dsl.Matcher) {
|
||||
m.Import("github.com/stretchr/testify/require")
|
||||
m.Import("github.com/stretchr/testify/assert")
|
||||
m.Import("github.com/coder/coder/testutil")
|
||||
|
||||
m.Match(`context.WithTimeout($ctx, $duration)`).
|
||||
Where(m.File().Imports("testing") && !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.")
|
||||
|
||||
m.Match(`
|
||||
$testify.$Eventually($t, func() bool {
|
||||
$*_
|
||||
}, $timeout, $interval, $*_)
|
||||
`).
|
||||
Where((m["testify"].Text == "require" || m["testify"].Text == "assert") &&
|
||||
(m["Eventually"].Text == "Eventually" || m["Eventually"].Text == "Eventuallyf") &&
|
||||
!m["timeout"].Text.Matches("^testutil\\.")).
|
||||
At(m["timeout"]).
|
||||
Report("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead.")
|
||||
|
||||
m.Match(`
|
||||
$testify.$Eventually($t, func() bool {
|
||||
$*_
|
||||
}, $timeout, $interval, $*_)
|
||||
`).
|
||||
Where((m["testify"].Text == "require" || m["testify"].Text == "assert") &&
|
||||
(m["Eventually"].Text == "Eventually" || m["Eventually"].Text == "Eventuallyf") &&
|
||||
!m["interval"].Text.Matches("^testutil\\.")).
|
||||
At(m["interval"]).
|
||||
Report("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead.")
|
||||
}
|
||||
|
||||
// InTx checks to ensure the database used inside the transaction closure is the transaction
|
||||
// database, and not the original database that creates the tx.
|
||||
func InTx(m dsl.Matcher) {
|
||||
|
Reference in New Issue
Block a user