diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-04-16 05:37:14 -0700 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-04-16 08:37:14 -0400 |
commit | 6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch) | |
tree | 3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/github.com/olivere/elastic/backoff_test.go | |
parent | bf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff) | |
download | chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2 chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip |
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/github.com/olivere/elastic/backoff_test.go')
-rw-r--r-- | vendor/github.com/olivere/elastic/backoff_test.go | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/vendor/github.com/olivere/elastic/backoff_test.go b/vendor/github.com/olivere/elastic/backoff_test.go deleted file mode 100644 index eae168a12..000000000 --- a/vendor/github.com/olivere/elastic/backoff_test.go +++ /dev/null @@ -1,140 +0,0 @@ -package elastic - -import ( - "math/rand" - "testing" - "time" -) - -func TestZeroBackoff(t *testing.T) { - b := ZeroBackoff{} - _, ok := b.Next(0) - if !ok { - t.Fatalf("expected %v, got %v", true, ok) - } -} - -func TestStopBackoff(t *testing.T) { - b := StopBackoff{} - _, ok := b.Next(0) - if ok { - t.Fatalf("expected %v, got %v", false, ok) - } -} - -func TestConstantBackoff(t *testing.T) { - b := NewConstantBackoff(time.Second) - d, ok := b.Next(0) - if !ok { - t.Fatalf("expected %v, got %v", true, ok) - } - if d != time.Second { - t.Fatalf("expected %v, got %v", time.Second, d) - } -} - -func TestSimpleBackoff(t *testing.T) { - var tests = []struct { - Duration time.Duration - Continue bool - }{ - // #0 - { - Duration: 1 * time.Millisecond, - Continue: true, - }, - // #1 - { - Duration: 2 * time.Millisecond, - Continue: true, - }, - // #2 - { - Duration: 7 * time.Millisecond, - Continue: true, - }, - // #3 - { - Duration: 0, - Continue: false, - }, - // #4 - { - Duration: 0, - Continue: false, - }, - } - - b := NewSimpleBackoff(1, 2, 7) - - for i, tt := range tests { - d, ok := b.Next(i) - if got, want := ok, tt.Continue; got != want { - t.Fatalf("#%d: expected %v, got %v", i, want, got) - } - if got, want := d, tt.Duration; got != want { - t.Fatalf("#%d: expected %v, got %v", i, want, got) - } - } -} - -func TestExponentialBackoff(t *testing.T) { - rand.Seed(time.Now().UnixNano()) - - min := time.Duration(8) * time.Millisecond - max := time.Duration(256) * time.Millisecond - b := NewExponentialBackoff(min, max) - - between := func(value time.Duration, a, b int) bool { - x := int(value / time.Millisecond) - return a <= x && x <= b - } - - got, ok := b.Next(0) - if !ok { - t.Fatalf("expected %v, got %v", true, ok) - } - if !between(got, 8, 256) { - t.Errorf("expected [%v..%v], got %v", 8, 256, got) - } - - got, ok = b.Next(1) - if !ok { - t.Fatalf("expected %v, got %v", true, ok) - } - if !between(got, 8, 256) { - t.Errorf("expected [%v..%v], got %v", 8, 256, got) - } - - got, ok = b.Next(2) - if !ok { - t.Fatalf("expected %v, got %v", true, ok) - } - if !between(got, 8, 256) { - t.Errorf("expected [%v..%v], got %v", 8, 256, got) - } - - got, ok = b.Next(3) - if !ok { - t.Fatalf("expected %v, got %v", true, ok) - } - if !between(got, 8, 256) { - t.Errorf("expected [%v..%v], got %v", 8, 256, got) - } - - got, ok = b.Next(4) - if !ok { - t.Fatalf("expected %v, got %v", true, ok) - } - if !between(got, 8, 256) { - t.Errorf("expected [%v..%v], got %v", 8, 256, got) - } - - if _, ok := b.Next(5); ok { - t.Fatalf("expected %v, got %v", false, ok) - } - - if _, ok = b.Next(6); ok { - t.Fatalf("expected %v, got %v", false, ok) - } -} |