Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix(cp-connector): fix passing deduplicated subjects to nats subscrib…
Browse files Browse the repository at this point in the history
…er (#7782)

fix(cp-connector): fix passing of subscription subjects to nats component

Signed-off-by: warber <bernd.warmuth@dynatrace.com>
  • Loading branch information
warber authored May 18, 2022
1 parent 18bcd6b commit 39124e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cp-connector/pkg/controlplane/eventsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (n *NATSEventSource) OnSubscriptionUpdate(subjects []string) {
n.logger.Errorf("Could not handle subscription update: %v", err)
return
}
if err := n.connector.QueueSubscribeMultiple(subjects, n.queueGroup, n.eventProcessFn); err != nil {
if err := n.connector.QueueSubscribeMultiple(s, n.queueGroup, n.eventProcessFn); err != nil {
n.logger.Errorf("Could not handle subscription update: %v", err)
return
}
Expand Down
19 changes: 19 additions & 0 deletions cp-connector/pkg/controlplane/eventsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ func TestEventSourceOnSubscriptionUpdate(t *testing.T) {
require.Equal(t, 2, natsConnectorMock.QueueSubscribeMultipleCalls)
}

func TestEventSourceOnSubscriptionupdateWithDuplicatedSubjects(t *testing.T) {
var receivedSubjects []string
natsConnectorMock := &NATSConnectorMock{
QueueSubscribeMultipleFn: func(subjects []string, queueGroup string, fn nats2.ProcessEventFn) error {
receivedSubjects = subjects
return nil
},
UnsubscribeAllFn: func() error { return nil },
}
eventSource := NewNATSEventSource(natsConnectorMock)
err := eventSource.Start(context.TODO(), RegistrationData{}, make(chan EventUpdate))
require.NoError(t, err)
require.Equal(t, 1, natsConnectorMock.QueueSubscribeMultipleCalls)
eventSource.OnSubscriptionUpdate([]string{"a", "a"})
require.Equal(t, 1, natsConnectorMock.UnsubscribeAllCalls)
require.Equal(t, 2, natsConnectorMock.QueueSubscribeMultipleCalls)
require.Equal(t, 1, len(receivedSubjects))
}

func TestEventSourceOnSubscriptiOnUpdateUnsubscribeAllFails(t *testing.T) {
natsConnectorMock := &NATSConnectorMock{
QueueSubscribeMultipleFn: func(subjects []string, queueGroup string, fn nats2.ProcessEventFn) error { return nil },
Expand Down

0 comments on commit 39124e1

Please sign in to comment.