Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Test icingaredis.SetChecksums() #799

wants to merge 1 commit into from

Conversation

Al2Klimov
Copy link
Member

No description provided.

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.

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