You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
go testsets its own timer to kill stuck tests. That timer is set unless -test.timeout is 0 (disabled) or if -test.fuzz is set. The go 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 plus go 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:
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
cespare
changed the title
cmd/go: do not apply a kill timeout to 'go test' if -test.bench was set
cmd/go: do not apply a kill timeout to 'go test' if -bench was set
Aug 31, 2024
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: