mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-09 06:25:40 +02:00
Some improvements for golint, ineffassign and misspell
This commit is contained in:
@@ -5,11 +5,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// RetryTicker is a wrapper aroung time.Tick,
|
||||
// that allows to mock its implementation
|
||||
type RetryTicker interface {
|
||||
Stop()
|
||||
Tick()
|
||||
}
|
||||
|
||||
// Ticker is a real implementation of RetryTicker interface
|
||||
type Ticker struct {
|
||||
ticker *time.Ticker
|
||||
}
|
||||
@@ -18,10 +21,7 @@ func (t *Ticker) Stop() { t.ticker.Stop() }
|
||||
|
||||
func (t *Ticker) Tick() { <-t.ticker.C }
|
||||
|
||||
// Retry calls ConditionFunc until either:
|
||||
// * it returns boolean true
|
||||
// * a timeout expires
|
||||
// * an error occurs
|
||||
// Retry is a wrapper around RetryWorker that provides a real RetryTicker
|
||||
func Retry(interval time.Duration, timeout time.Duration, f func() (bool, error)) error {
|
||||
//TODO: make the retry exponential
|
||||
if timeout < interval {
|
||||
@@ -31,6 +31,10 @@ func Retry(interval time.Duration, timeout time.Duration, f func() (bool, error)
|
||||
return RetryWorker(interval, timeout, tick, f)
|
||||
}
|
||||
|
||||
// RetryWorker calls ConditionFunc until either:
|
||||
// * it returns boolean true
|
||||
// * a timeout expires
|
||||
// * an error occurs
|
||||
func RetryWorker(
|
||||
interval time.Duration,
|
||||
timeout time.Duration,
|
||||
|
||||
@@ -13,7 +13,7 @@ type mockTicker struct {
|
||||
func (t *mockTicker) Stop() {}
|
||||
|
||||
func (t *mockTicker) Tick() {
|
||||
t.counter += 1
|
||||
t.counter++
|
||||
}
|
||||
|
||||
func TestRetryWorkerSuccess(t *testing.T) {
|
||||
@@ -36,13 +36,13 @@ func TestRetryWorkerOneFalse(t *testing.T) {
|
||||
|
||||
tick := &mockTicker{t, 0}
|
||||
result := RetryWorker(1, 3, tick, func() (bool, error) {
|
||||
counter += 1
|
||||
counter++
|
||||
|
||||
if counter <= 1 {
|
||||
return false, nil
|
||||
} else {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
})
|
||||
|
||||
if result != nil {
|
||||
|
||||
Reference in New Issue
Block a user