Conversation
oxzi
left a comment
There was a problem hiding this comment.
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.
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
ab60c73 to
8052ede
Compare
oxzi
left a comment
There was a problem hiding this comment.
I have rebased the PR branch onto main.
In general, looks mergeable to me, thanks.
No description provided.