Skip to content

Commit

Permalink
Restore expectedCount.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsha committed Jan 9, 2016
1 parent 62f1e66 commit d5acf9d
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions bdns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ func TestRetry(t *testing.T) {
servFailError := errors.New("DNS problem: server failure at resolver looking up TXT for example.com")
netError := errors.New("DNS problem: networking error looking up TXT for example.com")
type testCase struct {
maxTries int
te *testExchanger
expected error
maxTries int
te *testExchanger
expected error
expectedCount int
}
tests := []*testCase{
// The success on first try case
Expand All @@ -352,23 +353,26 @@ func TestRetry(t *testing.T) {
te: &testExchanger{
errs: []error{nil},
},
expected: nil,
expected: nil,
expectedCount: 1,
},
// Immediate non-OpError, error returns immediately
{
maxTries: 3,
te: &testExchanger{
errs: []error{errors.New("nope")},
},
expected: servFailError,
expected: servFailError,
expectedCount: 1,
},
// Temporary err, then non-OpError stops at two tries
{
maxTries: 3,
te: &testExchanger{
errs: []error{isTempErr, errors.New("nope")},
},
expected: servFailError,
expected: servFailError,
expectedCount: 2,
},
// Temporary error given always
{
Expand All @@ -380,7 +384,8 @@ func TestRetry(t *testing.T) {
isTempErr,
},
},
expected: netError,
expected: netError,
expectedCount: 3,
},
// Even with maxTries at 0, we should still let a single request go
// through
Expand All @@ -389,7 +394,8 @@ func TestRetry(t *testing.T) {
te: &testExchanger{
errs: []error{nil},
},
expected: nil,
expected: nil,
expectedCount: 1,
},
// Temporary error given just once causes two tries
{
Expand All @@ -400,7 +406,8 @@ func TestRetry(t *testing.T) {
nil,
},
},
expected: nil,
expected: nil,
expectedCount: 2,
},
// Temporary error given twice causes three tries
{
Expand All @@ -412,7 +419,8 @@ func TestRetry(t *testing.T) {
nil,
},
},
expected: nil,
expected: nil,
expectedCount: 3,
},
// Temporary error given thrice causes three tries and fails
{
Expand All @@ -424,7 +432,8 @@ func TestRetry(t *testing.T) {
isTempErr,
},
},
expected: netError,
expected: netError,
expectedCount: 3,
},
// temporary then non-Temporary error causes two retries
{
Expand All @@ -435,7 +444,8 @@ func TestRetry(t *testing.T) {
nonTempErr,
},
},
expected: netError,
expected: netError,
expectedCount: 2,
},
}

Expand All @@ -453,6 +463,9 @@ func TestRetry(t *testing.T) {
(expectedErr != nil && expectedErr.Error() != err.Error()) {
t.Errorf("#%d, error, expected %v, got %v", i, expectedErr, err)
}
if tc.expectedCount != tc.te.count {
t.Errorf("#%d, error, expectedCount %v, got %v", i, tc.expectedCount, tc.te.count)
}
}

dr := NewTestDNSResolverImpl(time.Second*10, []string{dnsLoopbackAddr}, testStats, clock.NewFake(), 3)
Expand Down

0 comments on commit d5acf9d

Please sign in to comment.