Skip to content

Commit

Permalink
refac: log entries and mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
WRichter72 committed Jan 29, 2025
1 parent 4be67c9 commit b9df6bb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
20 changes: 10 additions & 10 deletions internal/handler/delivering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func TestCheckDeliveringEvents_Success(t *testing.T) {
mockPicker := new(test.MockPicker)
test.InjectMockPicker(mockPicker)

deliveringHandler := new(test.DeliveringMockHandler)
cache.HandlerCache = deliveringHandler
handlerCache := new(test.MockHandlerCache)
cache.HandlerCache = handlerCache

deliveringHandler.On("NewLockContext", mock.Anything).Return(context.Background())
deliveringHandler.On("TryLockWithTimeout", mock.Anything, mock.Anything, mock.Anything).Return(true, nil)
deliveringHandler.On("Unlock", mock.Anything, mock.Anything).Return(nil)
handlerCache.On("NewLockContext", mock.Anything).Return(context.Background())
handlerCache.On("TryLockWithTimeout", mock.Anything, mock.Anything, mock.Anything).Return(true, nil)
handlerCache.On("Unlock", mock.Anything, mock.Anything).Return(nil)

config.Current.Republishing.BatchSize = 5
config.Current.Republishing.DeliveringStatesOffset = 30 * time.Minute
Expand Down Expand Up @@ -94,15 +94,15 @@ func TestCheckDeliveringEvents_NoEvents(t *testing.T) {
mockKafka := new(test.MockKafkaHandler)
kafka.CurrentHandler = mockKafka

deliveringHandler := new(test.DeliveringMockHandler)
cache.HandlerCache = deliveringHandler
handlerCache := new(test.MockHandlerCache)
cache.HandlerCache = handlerCache

mockPicker := new(test.MockPicker)
test.InjectMockPicker(mockPicker)

deliveringHandler.On("NewLockContext", mock.Anything).Return(context.Background())
deliveringHandler.On("TryLockWithTimeout", mock.Anything, mock.Anything, mock.Anything).Return(true, nil)
deliveringHandler.On("Unlock", mock.Anything, mock.Anything).Return(nil)
handlerCache.On("NewLockContext", mock.Anything).Return(context.Background())
handlerCache.On("TryLockWithTimeout", mock.Anything, mock.Anything, mock.Anything).Return(true, nil)
handlerCache.On("Unlock", mock.Anything, mock.Anything).Return(nil)

config.Current.Republishing.BatchSize = 5
config.Current.Republishing.DeliveringStatesOffset = 30 * time.Minute
Expand Down
10 changes: 5 additions & 5 deletions internal/handler/failed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ func TestCheckFailedEvents(t *testing.T) {
mockCache := new(test.SubscriptionMockCache)
cache.SubscriptionCache = mockCache

failedHandler := new(test.FailedMockHandler)
cache.HandlerCache = failedHandler
handlerCache := new(test.MockHandlerCache)
cache.HandlerCache = handlerCache

mockPicker := new(test.MockPicker)
test.InjectMockPicker(mockPicker)

failedHandler.On("NewLockContext", mock.Anything).Return(context.Background())
failedHandler.On("TryLockWithTimeout", mock.Anything, mock.Anything, mock.Anything).Return(true, nil)
failedHandler.On("Unlock", mock.Anything, mock.Anything).Return(nil)
handlerCache.On("NewLockContext", mock.Anything).Return(context.Background())
handlerCache.On("TryLockWithTimeout", mock.Anything, mock.Anything, mock.Anything).Return(true, nil)
handlerCache.On("Unlock", mock.Anything, mock.Anything).Return(nil)

config.Current.Republishing.BatchSize = 5

Expand Down
6 changes: 3 additions & 3 deletions internal/handler/waiting.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (waitingHandler *waitingHandler) CheckWaitingEvents() {
}

// If no subscriptions found, return
log.Debug().Msgf("Found %i subscriptions with waiting messages: %v", len(dbSubscriptionsForWaitingEvents), dbSubscriptionsForWaitingEvents)
log.Debug().Msgf("Found %d subscriptions with waiting messages: %v", len(dbSubscriptionsForWaitingEvents), dbSubscriptionsForWaitingEvents)
if len(dbSubscriptionsForWaitingEvents) == 0 {
return
}
Expand All @@ -66,15 +66,15 @@ func (waitingHandler *waitingHandler) CheckWaitingEvents() {
log.Error().Err(err).Msgf("Error while fetching rebublishing cache entries for events stucked in state WAITING")
return
}
log.Debug().Msgf("Found %i rebublishing entries: %v", len(republishingSubscriptionsMap), republishingSubscriptionsMap)
log.Debug().Msgf("Found %d rebublishing entries: %v", len(republishingSubscriptionsMap), republishingSubscriptionsMap)

// Get all circuit-breaker entries with status OPEN
circuitBreakerSubscriptionsMap, err := WaitingHandlerService.GetCircuitBreakerSubscriptionsMap()
if err != nil {
log.Error().Err(err).Msgf("Error while fetching circuit breaker cache entries for events stucked in state WAITING")
return
}
log.Debug().Msgf("Found %i circuitbreaker entries in state OPEN: %v", len(circuitBreakerSubscriptionsMap), circuitBreakerSubscriptionsMap)
log.Debug().Msgf("Found %d circuitbreaker entries in state OPEN: %v", len(circuitBreakerSubscriptionsMap), circuitBreakerSubscriptionsMap)

// Check if subscription is in republishing cache or in circuit breaker cache. If not create a republishing cache entry
for _, subscriptionId := range dbSubscriptionsForWaitingEvents {
Expand Down
4 changes: 4 additions & 0 deletions internal/test/waitinghandler_mock.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2025 Deutsche Telekom IT GmbH
//
// SPDX-License-Identifier: Apache-2.0

package test

import "github.com/stretchr/testify/mock"
Expand Down

0 comments on commit b9df6bb

Please sign in to comment.