forked from TrueCloudLab/restic
Update vendored library github.com/cenkalti/backoff
This commit is contained in:
parent
5a77b2ab49
commit
673f0bbd6c
9 changed files with 23 additions and 13 deletions
4
Gopkg.lock
generated
4
Gopkg.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
1
vendor/github.com/cenkalti/backoff/.travis.yml
generated
vendored
1
vendor/github.com/cenkalti/backoff/.travis.yml
generated
vendored
|
@ -1,6 +1,7 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.3.3
|
||||
- 1.x
|
||||
- tip
|
||||
before_install:
|
||||
- go get github.com/mattn/goveralls
|
||||
|
|
2
vendor/github.com/cenkalti/backoff/backoff.go
generated
vendored
2
vendor/github.com/cenkalti/backoff/backoff.go
generated
vendored
|
@ -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:
|
||||
//
|
||||
|
|
4
vendor/github.com/cenkalti/backoff/exponential.go
generated
vendored
4
vendor/github.com/cenkalti/backoff/exponential.go
generated
vendored
|
@ -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)
|
||||
}
|
||||
|
|
11
vendor/github.com/cenkalti/backoff/ticker.go
generated
vendored
11
vendor/github.com/cenkalti/backoff/ticker.go
generated
vendored
|
@ -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())
|
||||
|
|
4
vendor/github.com/cenkalti/backoff/ticker_test.go
generated
vendored
4
vendor/github.com/cenkalti/backoff/ticker_test.go
generated
vendored
|
@ -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 {
|
||||
|
|
4
vendor/github.com/cenkalti/backoff/tries.go
generated
vendored
4
vendor/github.com/cenkalti/backoff/tries.go
generated
vendored
|
@ -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}
|
||||
}
|
||||
|
||||
|
|
4
vendor/github.com/cenkalti/backoff/tries_test.go
generated
vendored
4
vendor/github.com/cenkalti/backoff/tries_test.go
generated
vendored
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue