Skip to content

Commit

Permalink
add unit tests for CreateXXXRetryPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
Vsevolod Kaloshin committed Dec 22, 2023
1 parent c62db3c commit 08b00d0
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"errors"
"fmt"
"github.com/uber/cadence/common/backoff"
"math/rand"
"strconv"
"sync"
Expand Down Expand Up @@ -478,3 +479,89 @@ func TestIsValidIDLength(t *testing.T) {
logger.AssertExpectations(t)
})
}

func TestCreateXXXRetryPolicyWithSetExpirationInterval(t *testing.T) {
for name, c := range map[string]struct {
createFn func() backoff.RetryPolicy

wantInitialInterval time.Duration
wantMaximumInterval time.Duration
wantSetExpirationInterval time.Duration
}{
"CreatePersistenceRetryPolicy": {
createFn: CreatePersistenceRetryPolicy,
wantInitialInterval: retryPersistenceOperationInitialInterval,
wantMaximumInterval: retryPersistenceOperationMaxInterval,
wantSetExpirationInterval: retryPersistenceOperationExpirationInterval,
},
"CreateHistoryServiceRetryPolicy": {
createFn: CreateHistoryServiceRetryPolicy,
wantInitialInterval: historyServiceOperationInitialInterval,
wantMaximumInterval: historyServiceOperationMaxInterval,
wantSetExpirationInterval: historyServiceOperationExpirationInterval,
},
"CreateMatchingServiceRetryPolicy": {
createFn: CreateMatchingServiceRetryPolicy,
wantInitialInterval: matchingServiceOperationInitialInterval,
wantMaximumInterval: matchingServiceOperationMaxInterval,
wantSetExpirationInterval: matchingServiceOperationExpirationInterval,
},
"CreateFrontendServiceRetryPolicy": {
createFn: CreateFrontendServiceRetryPolicy,
wantInitialInterval: frontendServiceOperationInitialInterval,
wantMaximumInterval: frontendServiceOperationMaxInterval,
wantSetExpirationInterval: frontendServiceOperationExpirationInterval,
},
"CreateAdminServiceRetryPolicy": {
createFn: CreateAdminServiceRetryPolicy,
wantInitialInterval: adminServiceOperationInitialInterval,
wantMaximumInterval: adminServiceOperationMaxInterval,
wantSetExpirationInterval: adminServiceOperationExpirationInterval,
},
"CreateReplicationServiceBusyRetryPolicy": {
createFn: CreateReplicationServiceBusyRetryPolicy,
wantInitialInterval: replicationServiceBusyInitialInterval,
wantMaximumInterval: replicationServiceBusyMaxInterval,
wantSetExpirationInterval: replicationServiceBusyExpirationInterval,
},
} {
t.Run(name, func(t *testing.T) {
want := backoff.NewExponentialRetryPolicy(c.wantInitialInterval)
want.SetMaximumInterval(c.wantMaximumInterval)
want.SetExpirationInterval(c.wantSetExpirationInterval)
got := c.createFn()
require.Equal(t, want, got)
})
}
}

func TestCreateXXXRetryPolicyWithMaximumAttempts(t *testing.T) {
for name, c := range map[string]struct {
createFn func() backoff.RetryPolicy

wantInitialInterval time.Duration
wantMaximumInterval time.Duration
wantMaximumAttempts int
}{
"CreateDlqPublishRetryPolicy": {
createFn: CreateDlqPublishRetryPolicy,
wantInitialInterval: retryKafkaOperationInitialInterval,
wantMaximumInterval: retryKafkaOperationMaxInterval,
wantMaximumAttempts: retryKafkaOperationMaxAttempts,
},
"CreateTaskProcessingRetryPolicy": {
createFn: CreateTaskProcessingRetryPolicy,
wantInitialInterval: retryTaskProcessingInitialInterval,
wantMaximumInterval: retryTaskProcessingMaxInterval,
wantMaximumAttempts: retryTaskProcessingMaxAttempts,
},
} {
t.Run(name, func(t *testing.T) {
want := backoff.NewExponentialRetryPolicy(c.wantInitialInterval)
want.SetMaximumInterval(c.wantMaximumInterval)
want.SetMaximumAttempts(c.wantMaximumAttempts)
got := c.createFn()
require.Equal(t, want, got)
})
}
}

0 comments on commit 08b00d0

Please sign in to comment.