-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: do not apply a kill timeout to 'go test' if -bench was set #69181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Milestone
Comments
This sounds reasonable to me. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Change https://go.dev/cl/648236 mentions this issue: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go version
go version go1.23.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
The code doesn't really matter, but for the sake of illustration suppose we have this benchmark:
(You can test this with any benchmark.) Consider the following
go test
invocations:go test -bench . -benchtime 70s -timeout 1s
go test -c -o x.test ./x/x_test.go && ./x.test -test.bench . -test.benchtime 70s -test.timeout 1s
What did you see happen?
The tests behave differently. When I run the test using
go test
, it kills the test after 61s:When I run the test binary, the
-test.timeout
flag has no effect and the benchmark runs to completion:What did you expect to see?
I would expect the program to behave the same way whether invoked via
go test
or compiled and run directly.What's going on here is a bit of a disagreement between the testing package and
go test
.The testing package applies the timeout to tests, fuzz tests, and examples, but not benchmarks. This is very much intentional; the old issue #18845 flagged a regression in this behavior and it was fixed in 4707045. The regression test is still around: it checks that running a 1s benchmark using
-timeout 750ms
should pass.go test
sets its own timer to kill stuck tests. That timer is set unless-test.timeout
is 0 (disabled) or if-test.fuzz
is set. Thego test
timer is set to the value of the test timeout plus one minute, since it expects the test to time itself out normally.So there is an inconsistency here.
I think we should resolve the inconsistency by changing
go test
not to time out test binaries if-test.bench
was set, as it already does for-test.fuzz
. The testing package clearly goes out of its way to avoid having-timeout
apply to benchmarks;go test
should respect that.This certainly comes up in practice. I work on a pretty large Go codebase. The 10m default test timeout works fine for us; our tests are generally plenty fast. But when I run benchmarks across lots of packages (this is common as part of the sanity checks when doing Go upgrades, for example) I usually forget to set
-timeout
and then after 11m my benchmarks are killed. (The odd 11m number is the 10m default timeout value plusgo test
's extra minute.)I noticed this when thinking about the related issue #48157 which is about adding per-test timeouts.
The text was updated successfully, but these errors were encountered: