From 673f0bbd6ce768961a20efda7f1d152e5d3e1406 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 30 Mar 2018 11:45:13 +0200 Subject: [PATCH] Update vendored library github.com/cenkalti/backoff --- Gopkg.lock | 4 ++-- internal/backend/backend_retry.go | 2 +- vendor/github.com/cenkalti/backoff/.travis.yml | 1 + vendor/github.com/cenkalti/backoff/backoff.go | 2 +- vendor/github.com/cenkalti/backoff/exponential.go | 4 +++- vendor/github.com/cenkalti/backoff/ticker.go | 11 +++++++---- vendor/github.com/cenkalti/backoff/ticker_test.go | 4 ++++ vendor/github.com/cenkalti/backoff/tries.go | 4 ++-- vendor/github.com/cenkalti/backoff/tries_test.go | 4 ++-- 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 004a63aea..c215f1b0e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -28,8 +28,8 @@ [[projects]] name = "github.com/cenkalti/backoff" packages = ["."] - revision = "61153c768f31ee5f130071d08fc82b85208528de" - version = "v1.1.0" + revision = "2ea60e5f094469f9e65adb9cd103795b73ae743e" + version = "v2.0.0" [[projects]] name = "github.com/cpuguy83/go-md2man" diff --git a/internal/backend/backend_retry.go b/internal/backend/backend_retry.go index 9f8834892..372d0a98f 100644 --- a/internal/backend/backend_retry.go +++ b/internal/backend/backend_retry.go @@ -34,7 +34,7 @@ func NewRetryBackend(be restic.Backend, maxTries int, report func(string, error, func (be *RetryBackend) retry(ctx context.Context, msg string, f func() error) error { err := backoff.RetryNotify(f, - backoff.WithContext(backoff.WithMaxTries(backoff.NewExponentialBackOff(), uint64(be.MaxTries)), ctx), + backoff.WithContext(backoff.WithMaxRetries(backoff.NewExponentialBackOff(), uint64(be.MaxTries)), ctx), func(err error, d time.Duration) { if be.Report != nil { be.Report(msg, err, d) diff --git a/vendor/github.com/cenkalti/backoff/.travis.yml b/vendor/github.com/cenkalti/backoff/.travis.yml index 1040404bf..d6f85ad6e 100644 --- a/vendor/github.com/cenkalti/backoff/.travis.yml +++ b/vendor/github.com/cenkalti/backoff/.travis.yml @@ -1,6 +1,7 @@ language: go go: - 1.3.3 + - 1.x - tip before_install: - go get github.com/mattn/goveralls diff --git a/vendor/github.com/cenkalti/backoff/backoff.go b/vendor/github.com/cenkalti/backoff/backoff.go index 2102c5f2d..3676ee405 100644 --- a/vendor/github.com/cenkalti/backoff/backoff.go +++ b/vendor/github.com/cenkalti/backoff/backoff.go @@ -15,7 +15,7 @@ import "time" // BackOff is a backoff policy for retrying an operation. type BackOff interface { // NextBackOff returns the duration to wait before retrying the operation, - // or backoff.Stop to indicate that no more retries should be made. + // or backoff. Stop to indicate that no more retries should be made. // // Example usage: // diff --git a/vendor/github.com/cenkalti/backoff/exponential.go b/vendor/github.com/cenkalti/backoff/exponential.go index 9a6addf07..d9de15a17 100644 --- a/vendor/github.com/cenkalti/backoff/exponential.go +++ b/vendor/github.com/cenkalti/backoff/exponential.go @@ -127,7 +127,9 @@ func (b *ExponentialBackOff) NextBackOff() time.Duration { // GetElapsedTime returns the elapsed time since an ExponentialBackOff instance // is created and is reset when Reset() is called. // -// The elapsed time is computed using time.Now().UnixNano(). +// The elapsed time is computed using time.Now().UnixNano(). It is +// safe to call even while the backoff policy is used by a running +// ticker. func (b *ExponentialBackOff) GetElapsedTime() time.Duration { return b.Clock.Now().Sub(b.startTime) } diff --git a/vendor/github.com/cenkalti/backoff/ticker.go b/vendor/github.com/cenkalti/backoff/ticker.go index 49a99718d..e742512fd 100644 --- a/vendor/github.com/cenkalti/backoff/ticker.go +++ b/vendor/github.com/cenkalti/backoff/ticker.go @@ -18,9 +18,12 @@ type Ticker struct { stopOnce sync.Once } -// NewTicker returns a new Ticker containing a channel that will send the time at times -// specified by the BackOff argument. Ticker is guaranteed to tick at least once. -// The channel is closed when Stop method is called or BackOff stops. +// NewTicker returns a new Ticker containing a channel that will send +// the time at times specified by the BackOff argument. Ticker is +// guaranteed to tick at least once. The channel is closed when Stop +// method is called or BackOff stops. It is not safe to manipulate the +// provided backoff policy (notably calling NextBackOff or Reset) +// while the ticker is running. func NewTicker(b BackOff) *Ticker { c := make(chan time.Time) t := &Ticker{ @@ -29,6 +32,7 @@ func NewTicker(b BackOff) *Ticker { b: ensureContext(b), stop: make(chan struct{}), } + t.b.Reset() go t.run() runtime.SetFinalizer(t, (*Ticker).Stop) return t @@ -42,7 +46,6 @@ func (t *Ticker) Stop() { func (t *Ticker) run() { c := t.c defer close(c) - t.b.Reset() // Ticker is guaranteed to tick at least once. afterC := t.send(time.Now()) diff --git a/vendor/github.com/cenkalti/backoff/ticker_test.go b/vendor/github.com/cenkalti/backoff/ticker_test.go index 085828cca..6aae254b3 100644 --- a/vendor/github.com/cenkalti/backoff/ticker_test.go +++ b/vendor/github.com/cenkalti/backoff/ticker_test.go @@ -30,6 +30,10 @@ func TestTicker(t *testing.T) { b := NewExponentialBackOff() ticker := NewTicker(b) + elapsed := b.GetElapsedTime() + if elapsed > time.Second { + t.Errorf("elapsed time too large: %v", elapsed) + } var err error for _ = range ticker.C { diff --git a/vendor/github.com/cenkalti/backoff/tries.go b/vendor/github.com/cenkalti/backoff/tries.go index d2da7308b..cfeefd9b7 100644 --- a/vendor/github.com/cenkalti/backoff/tries.go +++ b/vendor/github.com/cenkalti/backoff/tries.go @@ -3,13 +3,13 @@ package backoff import "time" /* -WithMaxTries creates a wrapper around another BackOff, which will +WithMaxRetries creates a wrapper around another BackOff, which will return Stop if NextBackOff() has been called too many times since the last time Reset() was called Note: Implementation is not thread-safe. */ -func WithMaxTries(b BackOff, max uint64) BackOff { +func WithMaxRetries(b BackOff, max uint64) BackOff { return &backOffTries{delegate: b, maxTries: max} } diff --git a/vendor/github.com/cenkalti/backoff/tries_test.go b/vendor/github.com/cenkalti/backoff/tries_test.go index bd1021143..f83c130b1 100644 --- a/vendor/github.com/cenkalti/backoff/tries_test.go +++ b/vendor/github.com/cenkalti/backoff/tries_test.go @@ -9,7 +9,7 @@ import ( func TestMaxTriesHappy(t *testing.T) { r := rand.New(rand.NewSource(time.Now().UnixNano())) max := 17 + r.Intn(13) - bo := WithMaxTries(&ZeroBackOff{}, uint64(max)) + bo := WithMaxRetries(&ZeroBackOff{}, uint64(max)) // Load up the tries count, but reset should clear the record for ix := 0; ix < max/2; ix++ { @@ -45,7 +45,7 @@ func TestMaxTriesHappy(t *testing.T) { func TestMaxTriesZero(t *testing.T) { // It might not make sense, but its okay to send a zero - bo := WithMaxTries(&ZeroBackOff{}, uint64(0)) + bo := WithMaxRetries(&ZeroBackOff{}, uint64(0)) for ix := 0; ix < 11; ix++ { d := bo.NextBackOff() if d == Stop {