Avoid resource leaks by recovering from panics in integration tests

This commit is contained in:
Matthew Riley 2018-01-19 23:07:38 -08:00
parent 0d47915beb
commit 580bbcb3ca

View file

@ -269,6 +269,15 @@ func (opts ProgramTestOptions) With(overrides ProgramTestOptions) ProgramTestOpt
func ProgramTest(t *testing.T, opts *ProgramTestOptions) {
t.Parallel()
// If the test panics, recover and log instead of letting the panic escape the test. Even though *this* test will
// have run deferred functions and cleaned up, if the panic reaches toplevel it will kill the process and prevent
// other tests running in parallel from cleaning up.
defer func() {
if failure := recover(); failure != nil {
t.Errorf("panic testing %v: %v", opts.Dir, failure)
}
}()
pt := newProgramTester(t, opts)
err := pt.testLifeCycleInitAndDestroy()
assert.NoError(t, err)