From dd4b63b7f8f9c0ff08baaf14403337d146e3f854 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 19 Jun 2026 12:19:57 +0100 Subject: [PATCH 1/2] Run the cleanup routines even if the main goroutine panics We should stop any running containers on panic, and things like complement-crypto expect their cleanup handlers to be run. --- test_main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test_main.go b/test_main.go index 39f87f5fe..ca5354b1b 100644 --- a/test_main.go +++ b/test_main.go @@ -76,12 +76,18 @@ func TestMain(m *testing.M, namespace string, customOpts ...opt) { fmt.Printf("Error: %s", err) os.Exit(1) } - exitCode := m.Run() - if opts.cleanup != nil { - opts.cleanup(testPackage.Config) + + // Run the cleanup functions even on panic. + runAndCleanup := func() int { + defer testPackage.Cleanup() + if opts.cleanup != nil { + defer opts.cleanup(testPackage.Config) + } + + return m.Run() } - testPackage.Cleanup() - os.Exit(exitCode) + + os.Exit(runAndCleanup()) } // Deploy will deploy the given blueprint or terminate the test. From 9d9a72fd561965ad5771b8319d29185a15d05152 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Sat, 20 Jun 2026 19:30:32 +0100 Subject: [PATCH 2/2] Apply suggestion from @richvdh --- test_main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_main.go b/test_main.go index ca5354b1b..a208a6aa5 100644 --- a/test_main.go +++ b/test_main.go @@ -78,6 +78,8 @@ func TestMain(m *testing.M, namespace string, customOpts ...opt) { } // Run the cleanup functions even on panic. + // Note that deferred functions aren't run on `os.Exit`, so we need to put the `defer` calls + // inside a new `func()`. runAndCleanup := func() int { defer testPackage.Cleanup() if opts.cleanup != nil {