@@ -81,6 +81,45 @@ func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) {
81
81
Report ("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)" )
82
82
}
83
83
84
+ // useStandardTimeoutsAndDelaysInTests ensures all tests use common
85
+ // constants for timeouts and delays in usual scenarios, this allows us
86
+ // to tweak them based on platform (important to avoid CI flakes).
87
+ //nolint:unused,deadcode,varnamelen
88
+ func useStandardTimeoutsAndDelaysInTests (m dsl.Matcher ) {
89
+ // m.Import("testing")
90
+ // m.Import("context")
91
+ m .Import ("github.com/stretchr/testify/require" )
92
+ m .Import ("github.com/stretchr/testify/assert" )
93
+ m .Import ("github.com/coder/coder/internal/testutil" )
94
+
95
+ m .Match (`context.WithTimeout($ctx, $duration)` ).
96
+ Where (m .File ().Imports ("testing" ) && ! m ["duration" ].Text .Matches ("^testutil\\ ." )).
97
+ At (m ["duration" ]).
98
+ Report ("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead." )
99
+
100
+ m .Match (`
101
+ $testify.$Eventually($t, func() bool {
102
+ $*_
103
+ }, $timeout, $interval, $*_)
104
+ ` ).
105
+ Where ((m ["testify" ].Text == "require" || m ["testify" ].Text == "assert" ) &&
106
+ (m ["Eventually" ].Text == "Eventually" || m ["Eventually" ].Text == "Eventuallyf" ) &&
107
+ ! m ["timeout" ].Text .Matches ("^testutil\\ ." )).
108
+ At (m ["timeout" ]).
109
+ Report ("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead." )
110
+
111
+ m .Match (`
112
+ $testify.$Eventually($t, func() bool {
113
+ $*_
114
+ }, $timeout, $interval, $*_)
115
+ ` ).
116
+ Where ((m ["testify" ].Text == "require" || m ["testify" ].Text == "assert" ) &&
117
+ (m ["Eventually" ].Text == "Eventually" || m ["Eventually" ].Text == "Eventuallyf" ) &&
118
+ ! m ["interval" ].Text .Matches ("^testutil\\ ." )).
119
+ At (m ["interval" ]).
120
+ Report ("Do not use magic numbers in test timeouts and delays. Use the standard testutil.Wait* or testutil.Interval* constants instead." )
121
+ }
122
+
84
123
// InTx checks to ensure the database used inside the transaction closure is the transaction
85
124
// database, and not the original database that creates the tx.
86
125
func InTx (m dsl.Matcher ) {
0 commit comments