Skip to content

Commit

Permalink
Merge pull request #36 from ricardo-ch/log-error-when-infinite-retry
Browse files Browse the repository at this point in the history
log error when there is an infinite retry pattern
  • Loading branch information
EdouardBavoux authored Apr 23, 2024
2 parents 7056d31 + f6a9d22 commit ecf0569
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ func (l *listener) handleMessageWithRetry(ctx context.Context, handler Handler,
time.Sleep(*handler.Config.DurationBeforeRetry)
if retries != InfiniteRetries {
retries--
} else {
ErrorLogger.Printf("Error for message with infinite retry %+v: ", err)
}
return l.handleMessageWithRetry(ctx, handler, msg, retries)
}
Expand Down
12 changes: 12 additions & 0 deletions listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ func Test_ConsumeClaim_Message_Error_WithErrorTopic(t *testing.T) {
Config: testHandlerConfig,
}

defaultLogger := ErrorLogger
defer func() { ErrorLogger = defaultLogger }()

errorLogged := false
mockLogger := &mocks.StdLogger{}
mockLogger.On("Printf", mock.Anything, mock.Anything).Return().Run(func(mock.Arguments) {
Expand Down Expand Up @@ -280,6 +283,9 @@ func Test_ConsumeClaim_Message_Error_WithPanicTopic(t *testing.T) {
Config: testHandlerConfig,
}

defaultLogger := ErrorLogger
defer func() { ErrorLogger = defaultLogger }()

errorLogged := false
mockLogger := &mocks.StdLogger{}
mockLogger.On("Printf", mock.Anything, mock.Anything).Return().Run(func(mock.Arguments) {
Expand Down Expand Up @@ -335,6 +341,9 @@ func Test_ConsumeClaim_Message_Error_WithHandlerSpecificRetryTopic(t *testing.T)
},
}

defaultLogger := ErrorLogger
defer func() { ErrorLogger = defaultLogger }()

errorLogged := false
mockLogger := &mocks.StdLogger{}
mockLogger.On("Printf", mock.Anything, mock.Anything).Return().Run(func(mock.Arguments) {
Expand Down Expand Up @@ -365,6 +374,9 @@ func Test_handleErrorMessage_OmittedError(t *testing.T) {

l := listener{}

defaultLogger := ErrorLogger
defer func() { ErrorLogger = defaultLogger }()

errorLogged := false
mockLogger := &mocks.StdLogger{}
mockLogger.On("Printf", "Omitted message: %+v", mock.Anything).Return().Run(func(mock.Arguments) {
Expand Down

0 comments on commit ecf0569

Please sign in to comment.