Skip to content

Commit

Permalink
Merge pull request #7 from yashipro13/fix/view-handler
Browse files Browse the repository at this point in the history
Fix the view handler to ensure, messages are viewed from RMQ
  • Loading branch information
Shivamcskk authored May 2, 2024
2 parents 19d0e43 + b24b8e2 commit 35380cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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

0 comments on commit 35380cf

Please sign in to comment.