Skip to content

Commit

Permalink
Merge pull request apache#811 from Dieterbe/test-simpleretrypolicy-mo…
Browse files Browse the repository at this point in the history
…re-thoroughly

test SimpleRetryPolicy more thoroughly
  • Loading branch information
Zariel authored Oct 26, 2016
2 parents ee3015e + 069c635 commit e1e2954
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,32 @@ func TestCOWList_Add(t *testing.T) {
}
}

// TestSimpleRetryPolicy makes sure that we only allow 1 + numRetries attempts
func TestSimpleRetryPolicy(t *testing.T) {
q := &Query{}

// this should allow a total of 3 tries.
rt := &SimpleRetryPolicy{NumRetries: 2}
if !rt.Attempt(q) {
t.Fatal("should allow retry after 0 attempts")
}
q.attempts = 5
if rt.Attempt(q) {
t.Fatal("should not allow retry after passing threshold")

cases := []struct {
attempts int
allow bool
}{
{0, true},
{1, true},
{2, true},
{3, false},
{4, false},
{5, false},
}

for _, c := range cases {
q.attempts = c.attempts
if c.allow && !rt.Attempt(q) {
t.Fatalf("should allow retry after %d attempts", c.attempts)
}
if !c.allow && rt.Attempt(q) {
t.Fatalf("should not allow retry after %d attempts", c.attempts)
}
}
}

0 comments on commit e1e2954

Please sign in to comment.