-
Notifications
You must be signed in to change notification settings - Fork 887
fix: Fix cleanup in test helpers, prefer defer
in tests
#3113
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 1 commit
9a5db33
628d9f2
2334d8a
d263af2
7b356b3
f245f64
b624871
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,7 @@ func newWithCloser(t *testing.T, options *Options) (*codersdk.Client, io.Closer) | |
} | ||
|
||
ctx, cancelFunc := context.WithCancel(context.Background()) | ||
t.Cleanup(cancelFunc) | ||
defer t.Cleanup(cancelFunc) // Defer to ensure cancelFunc is executed first. | ||
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. And here 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. Since this is a helper function, |
||
|
||
lifecycleExecutor := executor.New( | ||
ctx, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
defer cancelFunc()
not work here? I would expect defer to run before cleanups.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on the other instance: https://github.com/coder/coder/pull/3113/files#r928922910.