Skip to content

Commit

Permalink
Add a test case
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <amason@slack-corp.com>
  • Loading branch information
ajm188 committed Jul 2, 2020
1 parent be5c0e1 commit 9723a13
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions go/vt/mysqlctl/s3backupstorage/retryer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,77 @@ import (
"github.com/stretchr/testify/assert"
)

type testRetryer struct{}
type testRetryer struct{ retry bool }

func (r *testRetryer) MaxRetries() int { return 5 }
func (r *testRetryer) RetryRules(req *request.Request) time.Duration { return time.Second }
func (r *testRetryer) ShouldRetry(req *request.Request) bool { return false }
func (r *testRetryer) ShouldRetry(req *request.Request) bool { return r.retry }

func TestShouldRetry(t *testing.T) {
tests := []struct {
name string
r *request.Request
expected bool
name string
r *request.Request
fallbackPolicy bool
expected bool
}{

{
name: "non retryable request",
r: &request.Request{
Retryable: aws.Bool(false),
},
expected: false,
fallbackPolicy: false,
expected: false,
},
{
name: "retryable request",
r: &request.Request{
Retryable: aws.Bool(true),
},
expected: true,
fallbackPolicy: false,
expected: true,
},
{
name: "non aws error",
r: &request.Request{
Retryable: nil,
Error: errors.New("some error"),
},
expected: false,
fallbackPolicy: false,
expected: false,
},
{
name: "closed connection error",
r: &request.Request{
Retryable: nil,
Error: awserr.New("5xx", "use of closed network connection", nil),
},
expected: true,
fallbackPolicy: false,
expected: true,
},
{
name: "closed connection error (non nil origError)",
r: &request.Request{
Retryable: nil,
Error: awserr.New("5xx", "use of closed network connection", errors.New("some error")),
},
expected: true,
fallbackPolicy: false,
expected: true,
},
{
name: "other aws error hits fallback policy",
r: &request.Request{
Retryable: nil,
Error: awserr.New("code", "not a closed network connectionn", errors.New("some error")),
},
fallbackPolicy: true,
expected: true,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
retryer := &ClosedConnectionRetryer{&testRetryer{}}
retryer := &ClosedConnectionRetryer{&testRetryer{test.fallbackPolicy}}
msg := ""
if test.r.Error != nil {
if awsErr, ok := test.r.Error.(awserr.Error); ok {
Expand Down

0 comments on commit 9723a13

Please sign in to comment.