Skip to content

proposal: testing: consider having timeouts in test binaries be recoverable/handled #44929

@dprotaso

Description

@dprotaso

The way timeouts are thrown cause the binary to exit immediately

go/src/testing/testing.go

Lines 1740 to 1744 in 4d608eb

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

  1. when a timeout occurs run T.Cleanup functions
  2. 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()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions