This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vitessio#6395 from tinyspeck/am_fix_retryer
Fix segfault in backup retryer
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package s3backupstorage | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type testRetryer struct{} | ||
|
||
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 TestShouldRetry(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
r *request.Request | ||
expected bool | ||
}{ | ||
|
||
{ | ||
name: "non retryable request", | ||
r: &request.Request{ | ||
Retryable: aws.Bool(false), | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "retryable request", | ||
r: &request.Request{ | ||
Retryable: aws.Bool(true), | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "non aws error", | ||
r: &request.Request{ | ||
Retryable: nil, | ||
Error: errors.New("some error"), | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "closed connection error", | ||
r: &request.Request{ | ||
Retryable: nil, | ||
Error: awserr.New("5xx", "use of closed network connection", nil), | ||
}, | ||
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, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
retryer := &ClosedConnectionRetryer{&testRetryer{}} | ||
msg := "" | ||
if test.r.Error != nil { | ||
if awsErr, ok := test.r.Error.(awserr.Error); ok { | ||
msg = awsErr.Error() | ||
} | ||
} | ||
assert.Equal(t, test.expected, retryer.ShouldRetry(test.r), msg) | ||
}) | ||
} | ||
} |