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

Fix the view handler to ensure, messages are viewed from RMQ #7

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions mw/rabbitmq/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func Test_view(t *testing.T) {
viewCount int
expectedViewCount int
name string
expectedMessages []string
}

cases := []test{
Expand All @@ -121,27 +122,31 @@ func Test_view(t *testing.T) {
publishCount: 5,
viewCount: 5,
expectedViewCount: 5,
expectedMessages: []string{"bar-0", "bar-1", "bar-2", "bar-3", "bar-4"},
},
{
name: "read excess number of messages than there are in the queue",
qname: "foo",
publishCount: 5,
viewCount: 10,
expectedViewCount: 5,
expectedMessages: []string{"bar-0", "bar-1", "bar-2", "bar-3", "bar-4"},
},
{
name: "read negative number of messages",
qname: "foo",
publishCount: 5,
viewCount: -1,
expectedViewCount: 0,
expectedMessages: []string{},
},
{
name: "read zero messages",
qname: "foo",
viewCount: 0,
publishCount: 5,
expectedViewCount: 0,
expectedMessages: []string{},
}}

for _, c := range cases {
Expand All @@ -161,12 +166,18 @@ func Test_view(t *testing.T) {
}
}
queueName := fmt.Sprintf("%s_%s_%s", c.qname, "dlq", "queue")
events, err := ar.view(ctx, queueName, c.viewCount, false)
viewEventsOnce, err := ar.view(ctx, queueName, c.viewCount, false)
viewEventsTwice, err := ar.view(ctx, queueName, c.viewCount, false)
if err != nil {
t.Errorf("error viewing messages: %v", err)
}
if len(events) != c.expectedViewCount {
t.Errorf("expected to read %d messages but read %d", c.expectedViewCount, len(events))
if len(viewEventsOnce) != c.expectedViewCount {
t.Errorf("expected to read %d messages but read %d", c.expectedViewCount, len(viewEventsOnce))
}
for idx, event := range c.expectedMessages {
if string(viewEventsOnce[idx].Value) != event || string(viewEventsTwice[idx].Value) != event {
t.Errorf("expected message %s but got %s", event, string(viewEventsOnce[idx].Value))
}
}
err = ar.DeleteQueuesAndExchanges(context.Background(), c.qname)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions mw/rabbitmq/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ func (r *ARetry) view(ctx context.Context, qnameWithType string, count int, ack
var ackErr error
if ack {
ackErr = msg.Ack(true)
} else {
ackErr = msg.Reject(true)
}

r.ogLogger.Error("", ackErr)
Expand Down
Loading