-
Notifications
You must be signed in to change notification settings - Fork 20
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
Test icingaredis.SetChecksums() #799
base: main
Are you sure you want to change the base?
Conversation
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.
For both functions, tests against a prematurely canceled context are missing.
select { | ||
case <-time.After(l.latency): | ||
case <-ctx.Done(): | ||
return |
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.
Indentation depth eleven. We're hitting indentation levels that shouldn't even be possible :>
If the input channel blocks since its creation forever and the context has always been canceled, do you expect the output channel to get closed immediately? --- pkg/icingaredis/utils_test.go
+++ pkg/icingaredis/utils_test.go
@@ -346,4 +346,29 @@ func TestSetChecksums(t *testing.T) {
}
})
}
+
+ t.Run("cancel-ctx", func(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ output, errs := SetChecksums(ctx, make(chan database.Entity), map[string]database.Entity{}, 1)
+
+ require.NotNil(t, output, "output channel should not be nil")
+ require.NotNil(t, errs, "error channel should not be nil")
+
+ select {
+ case v, ok := <-output:
+ require.False(t, ok, "output channel should be closed, got %#v", v)
+ case <-time.After(time.Second):
+ require.Fail(t, "output channel should not block")
+ }
+
+ select {
+ case err, ok := <-errs:
+ require.True(t, ok, "error channel should not be closed, yet")
+ require.Error(t, err)
+ case <-time.After(time.Second):
+ require.Fail(t, "error channel should not block")
+ }
+ })
} |
I guess so, yes. However, the current implementation should skip closing the output channel, as it happens deferred in the |
597ac8b
to
9a76f85
Compare
9a76f85
to
e5dc8b8
Compare
No description provided.