-
Notifications
You must be signed in to change notification settings - Fork 887
fix: Move timeout ctx closer to use in tests, increase timeout #3109
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 |
---|---|---|
|
@@ -48,7 +48,7 @@ func TestCaching(t *testing.T) { | |
defer srv.Close() | ||
|
||
// Create a context | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second) | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second) | ||
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. (Idea, out-of-scope): should we have a "standard" set of timeouts we use for all unit tests? 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 really like that idea! It's all over the place now and doesn't allow us to easily adjust for slow/fast platforms. |
||
defer cancelFunc() | ||
|
||
testCases := []struct { | ||
|
@@ -108,7 +108,7 @@ func TestServingFiles(t *testing.T) { | |
defer srv.Close() | ||
|
||
// Create a context | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second) | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancelFunc() | ||
|
||
testCases := []struct { | ||
|
@@ -337,7 +337,7 @@ func TestServingBin(t *testing.T) { | |
defer srv.Close() | ||
|
||
// Create a context | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second) | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancelFunc() | ||
|
||
for _, tr := range tt.reqs { | ||
|
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.
Why
defer
here overt.Cleanup
?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.
I feel tests should prefer to read like idiomatic Go code,
t.Cleanup
is useful for helper functions but has no benefit overdefer
.It could also lead to logic bugs where there are defers and
t.Cleanup
mixed, because the order of execution would differ.This would execute in the following order:
close3, close1, close2
likely leading to a logic bug.