mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-22 10:38:30 +02:00
Change the order of arguments
This commit is contained in:
@@ -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)
|
return fmt.Errorf("timout(%s) should be greater than interval(%v)", timeout, interval)
|
||||||
}
|
}
|
||||||
tick := &Ticker{time.NewTicker(interval)}
|
tick := &Ticker{time.NewTicker(interval)}
|
||||||
return RetryWorker(interval, timeout, f, tick)
|
return RetryWorker(interval, timeout, tick, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RetryWorker(
|
func RetryWorker(
|
||||||
interval time.Duration,
|
interval time.Duration,
|
||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
f func() (bool, error),
|
tick RetryTicker,
|
||||||
tick RetryTicker) error {
|
f func() (bool, error)) error {
|
||||||
|
|
||||||
maxRetries := int(timeout / interval)
|
maxRetries := int(timeout / interval)
|
||||||
defer tick.Stop()
|
defer tick.Stop()
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ func (t *mockTicker) Tick() {
|
|||||||
|
|
||||||
func TestRetryWorkerSuccess(t *testing.T) {
|
func TestRetryWorkerSuccess(t *testing.T) {
|
||||||
tick := &mockTicker{t, 0}
|
tick := &mockTicker{t, 0}
|
||||||
result := RetryWorker(10, 20, func() (bool, error) {
|
result := RetryWorker(10, 20, tick, func() (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}, tick)
|
})
|
||||||
|
|
||||||
if result != nil {
|
if result != nil {
|
||||||
t.Errorf("Wrong result, expected: %#v, got: %#v", nil, result)
|
t.Errorf("Wrong result, expected: %#v, got: %#v", nil, result)
|
||||||
@@ -35,7 +35,7 @@ func TestRetryWorkerOneFalse(t *testing.T) {
|
|||||||
var counter = 0
|
var counter = 0
|
||||||
|
|
||||||
tick := &mockTicker{t, 0}
|
tick := &mockTicker{t, 0}
|
||||||
result := RetryWorker(1, 3, func() (bool, error) {
|
result := RetryWorker(1, 3, tick, func() (bool, error) {
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
if counter <= 1 {
|
if counter <= 1 {
|
||||||
@@ -43,7 +43,7 @@ func TestRetryWorkerOneFalse(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}, tick)
|
})
|
||||||
|
|
||||||
if result != nil {
|
if result != nil {
|
||||||
t.Errorf("Wrong result, expected: %#v, got: %#v", nil, result)
|
t.Errorf("Wrong result, expected: %#v, got: %#v", nil, result)
|
||||||
@@ -58,9 +58,9 @@ func TestRetryWorkerError(t *testing.T) {
|
|||||||
fail := errors.New("Error")
|
fail := errors.New("Error")
|
||||||
|
|
||||||
tick := &mockTicker{t, 0}
|
tick := &mockTicker{t, 0}
|
||||||
result := RetryWorker(1, 3, func() (bool, error) {
|
result := RetryWorker(1, 3, tick, func() (bool, error) {
|
||||||
return false, fail
|
return false, fail
|
||||||
}, tick)
|
})
|
||||||
|
|
||||||
if result != fail {
|
if result != fail {
|
||||||
t.Errorf("Wrong result, expected: %#v, got: %#v", fail, result)
|
t.Errorf("Wrong result, expected: %#v, got: %#v", fail, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user