Skip to content

Commit

Permalink
Rename var
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Santos committed Oct 26, 2023
1 parent 549ad47 commit ead8de5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions core/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type AsyncActionHandler[T any] struct {
sleepBeforeWait time.Duration
throttle time.Duration
timeout time.Duration
retryLimitTempErr int
tempErrRetryLimit int
}

// New initializes an AsyncActionHandler
Expand All @@ -34,7 +34,7 @@ func New[T any](f AsyncActionCheck[T]) *AsyncActionHandler[T] {
sleepBeforeWait: 0 * time.Second,
throttle: 5 * time.Second,
timeout: 30 * time.Minute,
retryLimitTempErr: 5,
tempErrRetryLimit: 5,
}
}

Expand All @@ -56,10 +56,10 @@ func (h *AsyncActionHandler[T]) SetSleepBeforeWait(d time.Duration) *AsyncAction
return h
}

// SetRetryLimitTempErr sets the retry limit if a temporary error is found.
// SetTempErrRetryLimit sets the retry limit if a temporary error is found.
// The list of temporary errors is defined in the RetryHttpErrorStatusCodes variable.
func (h *AsyncActionHandler[T]) SetRetryLimitTempErr(l int) *AsyncActionHandler[T] {
h.retryLimitTempErr = l
func (h *AsyncActionHandler[T]) SetTempErrRetryLimit(l int) *AsyncActionHandler[T] {
h.tempErrRetryLimit = l
return h
}

Expand Down Expand Up @@ -110,7 +110,7 @@ func (h *AsyncActionHandler[T]) handleError(retryTempErrorCounter int, err error
return retryTempErrorCounter, err
}
retryTempErrorCounter++
if retryTempErrorCounter == h.retryLimitTempErr {
if retryTempErrorCounter == h.tempErrRetryLimit {
return retryTempErrorCounter, fmt.Errorf("temporary error was found and the retry limit was reached: %w", err)
}
return retryTempErrorCounter, nil
Expand Down
38 changes: 19 additions & 19 deletions core/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestNew(t *testing.T) {
sleepBeforeWait: 0 * time.Second,
throttle: 5 * time.Second,
timeout: 30 * time.Minute,
retryLimitTempErr: 5,
tempErrRetryLimit: 5,
}

diff := cmp.Diff(got, want, cmpOpts...)
Expand Down Expand Up @@ -224,12 +224,12 @@ func TestSetSleepBeforeWait(t *testing.T) {
}
}

func TestSetRetryLimitTempErr(t *testing.T) {
func TestSetTempErrRetryLimit(t *testing.T) {
checkFn := func() (waitFinished bool, res *interface{}, err error) { return true, nil, nil }

for _, tt := range []struct {
desc string
retryLimitTempErr int
tempErrRetryLimit int
}{
{
"base_1",
Expand All @@ -242,9 +242,9 @@ func TestSetRetryLimitTempErr(t *testing.T) {
} {
t.Run(tt.desc, func(t *testing.T) {
want := New(checkFn)
want.retryLimitTempErr = tt.retryLimitTempErr
want.tempErrRetryLimit = tt.tempErrRetryLimit
got := New(checkFn)
got.SetRetryLimitTempErr(tt.retryLimitTempErr)
got.SetTempErrRetryLimit(tt.tempErrRetryLimit)

diff := cmp.Diff(got, want, cmpOpts...)
if diff != "" {
Expand Down Expand Up @@ -293,7 +293,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait time.Duration
handlerThrottle time.Duration
handlerTimeout time.Duration
handlerRetryLimitTempErr int
handlerTempErrRetryLimit int
contextTimeout time.Duration
wantCheckFnNumberCalls int
wantErr bool
Expand All @@ -306,7 +306,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 100 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 100 * time.Millisecond,
wantCheckFnNumberCalls: 1,
wantErr: false,
Expand All @@ -319,7 +319,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 0 * time.Millisecond,
handlerTimeout: 100 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 100 * time.Millisecond,
wantCheckFnNumberCalls: 0,
wantErr: true,
Expand All @@ -332,7 +332,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 100 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 100 * time.Millisecond,
wantCheckFnNumberCalls: 3,
wantErr: false,
Expand All @@ -345,7 +345,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 100 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 1000 * time.Millisecond,
wantCheckFnNumberCalls: 4,
wantErr: true,
Expand All @@ -358,7 +358,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 1000 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 100 * time.Millisecond,
wantCheckFnNumberCalls: 4,
wantErr: true,
Expand All @@ -371,7 +371,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 60 * time.Millisecond,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 100 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 100 * time.Millisecond,
wantCheckFnNumberCalls: 2,
wantErr: true,
Expand All @@ -384,7 +384,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 200 * time.Millisecond,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 100 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 1000 * time.Millisecond,
wantCheckFnNumberCalls: 1,
wantErr: true,
Expand All @@ -397,7 +397,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 200 * time.Millisecond,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 1000 * time.Millisecond,
handlerRetryLimitTempErr: 0,
handlerTempErrRetryLimit: 0,
contextTimeout: 100 * time.Millisecond,
wantCheckFnNumberCalls: 1,
wantErr: true,
Expand All @@ -411,7 +411,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 1000 * time.Millisecond,
handlerRetryLimitTempErr: 5,
handlerTempErrRetryLimit: 5,
contextTimeout: 1000 * time.Millisecond,
wantCheckFnNumberCalls: 1,
wantErr: true,
Expand All @@ -425,7 +425,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 1000 * time.Millisecond,
handlerRetryLimitTempErr: 5,
handlerTempErrRetryLimit: 5,
contextTimeout: 1000 * time.Millisecond,
wantCheckFnNumberCalls: 5,
wantErr: true,
Expand All @@ -439,7 +439,7 @@ func TestWaitWithContext(t *testing.T) {
handlerSleepBeforeWait: 0,
handlerThrottle: 30 * time.Millisecond,
handlerTimeout: 1000 * time.Millisecond,
handlerRetryLimitTempErr: 5,
handlerTempErrRetryLimit: 5,
contextTimeout: 1000 * time.Millisecond,
wantCheckFnNumberCalls: 3,
wantErr: false,
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestWaitWithContext(t *testing.T) {
sleepBeforeWait: tt.handlerSleepBeforeWait,
throttle: tt.handlerThrottle,
timeout: tt.handlerTimeout,
retryLimitTempErr: tt.handlerRetryLimitTempErr,
tempErrRetryLimit: tt.handlerTempErrRetryLimit,
}
ctx, cancel := context.WithTimeout(context.Background(), tt.contextTimeout)
defer cancel()
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestHandleError(t *testing.T) {
} {
t.Run(tt.desc, func(t *testing.T) {
w := &AsyncActionHandler[interface{}]{
retryLimitTempErr: tt.tempErrRetryLimit,
tempErrRetryLimit: tt.tempErrRetryLimit,
}
_, err := w.handleError(0, tt.reqErr)
if (err != nil) != tt.wantErr {
Expand Down

0 comments on commit ead8de5

Please sign in to comment.