Change the order of arguments

This commit is contained in:
Dmitrii Dolgov 2018-02-08 10:43:27 +01:00
parent dd79fcd036
commit 4c1db33c27
2 changed files with 9 additions and 9 deletions

View File

@ -28,14 +28,14 @@ func Retry(interval time.Duration, timeout time.Duration, f func() (bool, error)
return fmt.Errorf("timout(%s) should be greater than interval(%v)", timeout, interval)
}
tick := &Ticker{time.NewTicker(interval)}
return RetryWorker(interval, timeout, f, tick)
return RetryWorker(interval, timeout, tick, f)
}
func RetryWorker(
interval time.Duration,
timeout time.Duration,
f func() (bool, error),
tick RetryTicker) error {
tick RetryTicker,
f func() (bool, error)) error {
maxRetries := int(timeout / interval)
defer tick.Stop()

View File

@ -18,9 +18,9 @@ func (t *mockTicker) Tick() {
func TestRetryWorkerSuccess(t *testing.T) {
tick := &mockTicker{t, 0}
result := RetryWorker(10, 20, func() (bool, error) {
result := RetryWorker(10, 20, tick, func() (bool, error) {
return true, nil
}, tick)
})
if result != nil {
t.Errorf("Wrong result, expected: %#v, got: %#v", nil, result)
@ -35,7 +35,7 @@ func TestRetryWorkerOneFalse(t *testing.T) {
var counter = 0
tick := &mockTicker{t, 0}
result := RetryWorker(1, 3, func() (bool, error) {
result := RetryWorker(1, 3, tick, func() (bool, error) {
counter += 1
if counter <= 1 {
@ -43,7 +43,7 @@ func TestRetryWorkerOneFalse(t *testing.T) {
} else {
return true, nil
}
}, tick)
})
if result != nil {
t.Errorf("Wrong result, expected: %#v, got: %#v", nil, result)
@ -58,9 +58,9 @@ func TestRetryWorkerError(t *testing.T) {
fail := errors.New("Error")
tick := &mockTicker{t, 0}
result := RetryWorker(1, 3, func() (bool, error) {
result := RetryWorker(1, 3, tick, func() (bool, error) {
return false, fail
}, tick)
})
if result != fail {
t.Errorf("Wrong result, expected: %#v, got: %#v", fail, result)