panic(fmt.Sprintf("test timed out after %v", *timeout))
})
This circumvents T.Cleanup and any cleanup logic that might have been in TestMain. In order to guarantee setup/teardown occurs it has to be done outside the go test process. Thus either a testing script or the use of go test -exec xprog
The challenge with these workarounds is you lose the simplicity of invoking go test.
Thus my ask is
when a timeout occurs run T.Cleanup functions
considering surfacing the timeout as a panic but allow the ability to handle that panic
My second point could be accomplished by having the panic be surfaced by M.Run() and could be handled in the following way
The text was updated successfully, but these errors were encountered:
dprotaso
changed the title
consider having timeouts in test binaries exit gracefully
consider having timeouts in test binaries be recoverable/handled
Mar 10, 2021
Note that the t.Deadline method was introduced specifically so that tests could arrange their own, earlier, timeouts.
ianlancetaylor
changed the title
consider having timeouts in test binaries be recoverable/handled
testing: consider having timeouts in test binaries be recoverable/handled
Mar 10, 2021
ianlancetaylor
changed the title
testing: consider having timeouts in test binaries be recoverable/handled
proposal: testing: consider having timeouts in test binaries be recoverable/handled
Mar 10, 2021
The way timeouts are thrown cause the binary to exit immediately
go/src/testing/testing.go
Lines 1740 to 1744 in 4d608eb
This circumvents
T.Cleanup
and any cleanup logic that might have been inTestMain
. In order to guarantee setup/teardown occurs it has to be done outside thego test
process. Thus either a testing script or the use ofgo test -exec xprog
The challenge with these workarounds is you lose the simplicity of invoking
go test
.Thus my ask is
T.Cleanup
functionsMy second point could be accomplished by having the panic be surfaced by
M.Run()
and could be handled in the following wayThe text was updated successfully, but these errors were encountered: