-
Notifications
You must be signed in to change notification settings - Fork 69
Run the cleanup routines even if the main goroutine panics #882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,12 +76,20 @@ 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. | ||||||||||||||||||||||||||||||||||||||||
| // 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 { | ||||||||||||||||||||||||||||||||||||||||
| defer opts.cleanup(testPackage.Config) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return m.Run() | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| testPackage.Cleanup() | ||||||||||||||||||||||||||||||||||||||||
| os.Exit(exitCode) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| os.Exit(runAndCleanup()) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+80
to
+92
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this also work? (less layers)
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. Per https://pkg.go.dev/os#Exit, deferred functions are not run on I'll add a comment to clarify this. |
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Deploy will deploy the given blueprint or terminate the test. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.