The way timeouts are thrown cause the binary to exit immediately
|
m.timer = time.AfterFunc(*timeout, func() { |
|
m.after() |
|
debug.SetTraceback("all") |
|
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
func TestMain(m *testing.M) {
os.Exit(run(m))
}
func run(m *testing.M) (exitCode int) {
setup()
defer cleanup()
exitCode = m.Run()
}
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.Cleanupand any cleanup logic that might have been inTestMain. In order to guarantee setup/teardown occurs it has to be done outside thego testprocess. Thus either a testing script or the use ofgo test -exec xprogThe challenge with these workarounds is you lose the simplicity of invoking
go test.Thus my ask is
T.CleanupfunctionsMy second point could be accomplished by having the panic be surfaced by
M.Run()and could be handled in the following way