doNotCallTFailNowInsideGoroutine enforces not calling t.FailNow or functions that may themselves call t.FailNow in goroutines outside the main test goroutine. See testing.go:834 for why. nolint:unused,deadcode,varnamelen
(m dsl.Matcher)
| 181 | // |
| 182 | //nolint:unused,deadcode,varnamelen |
| 183 | func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) { |
| 184 | m.Import("testing") |
| 185 | m.Match(` |
| 186 | go func($*_){ |
| 187 | $*_ |
| 188 | require.$_($*_) |
| 189 | $*_ |
| 190 | }($*_)`). |
| 191 | Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)") |
| 192 | |
| 193 | // require.Eventually runs the function in a goroutine. |
| 194 | m.Match(` |
| 195 | require.Eventually(t, func() bool { |
| 196 | $*_ |
| 197 | require.$_($*_) |
| 198 | $*_ |
| 199 | }, $*_)`). |
| 200 | Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)") |
| 201 | |
| 202 | m.Match(` |
| 203 | go func($*_){ |
| 204 | $*_ |
| 205 | t.$fail($*_) |
| 206 | $*_ |
| 207 | }($*_)`). |
| 208 | At(m["fail"]). |
| 209 | Where(m["fail"].Text.Matches("^(FailNow|Fatal|Fatalf)$")). |
| 210 | Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)") |
| 211 | } |
| 212 | |
| 213 | // useStandardTimeoutsAndDelaysInTests ensures all tests use common |
| 214 | // constants for timeouts and delays in usual scenarios, this allows us |