Skip to content

Conversation

Al2Klimov
Copy link
Member

No description provided.

@cla-bot cla-bot bot added the cla/signed label Sep 5, 2024
@Al2Klimov Al2Klimov requested a review from oxzi September 6, 2024 11:45
Copy link
Member

@oxzi oxzi left a 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
Copy link
Member

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 :>

@Al2Klimov
Copy link
Member Author

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")
+               }
+       })
 }

@oxzi
Copy link
Member

oxzi commented Sep 24, 2024

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?

I guess so, yes. However, the current implementation should skip closing the output channel, as it happens deferred in the errgroup goroutine.

@Al2Klimov Al2Klimov removed their assignment Aug 20, 2025
@Al2Klimov Al2Klimov requested a review from oxzi August 20, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants