From: Michael Pratt Date: Mon, 18 Oct 2021 22:34:24 +0000 (-0400) Subject: testing: skip extra -count iterations if there are no tests X-Git-Tag: go1.18beta1~782 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2c66cab8a7b569b2dc5a7ab112ba4579f39c5dbb;p=gostls13.git testing: skip extra -count iterations if there are no tests When running benchmarks with high -count and no tests (either at all or filtered with -run), the time for runTests to check for tests -count times can add a significant delay to starting benchmarks. To avoid this delay, make runTests bail out on the second iteration if the first found no tests to run. We expect the same tests to run every time, so there is no reason to duplicate work. One caveat: the testing docs do not explicitly require the same subtests to be run on every call, so this could break tests that depend on multiple runs to actually run all tests. I consider such tests invalid, but some may exist. Fixes #49050 Change-Id: I7b34f3832b31493cc089ee0555e231f4dc690154 Reviewed-on: https://go-review.googlesource.com/c/go/+/356669 Trust: Michael Pratt Run-TryBot: Michael Pratt TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor --- diff --git a/src/testing/testing.go b/src/testing/testing.go index 6fb1a71d43..2ad2266e2d 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -1785,6 +1785,12 @@ func runTests(matchString func(pat, str string) (bool, error), tests []InternalT if shouldFailFast() { break } + if i > 0 && !ran { + // There were no tests to run on the first + // iteration. This won't change, so no reason + // to keep trying. + break + } ctx := newTestContext(*parallel, newMatcher(matchString, *match, "-test.run")) ctx.deadline = deadline t := &T{