Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 5a095dc

Browse files
committed
Fixup request retry override test behavior
1 parent cd6ddb5 commit 5a095dc

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ SDK_TESTING_PKGS=./awstesting/...
2020
SDK_MODELS_PKGS=./models/...
2121
SDK_ALL_PKGS=${SDK_COMPA_PKGS} ${SDK_TESTING_PKGS} ${SDK_EXAMPLES_PKGS} ${SDK_MODELS_PKGS}
2222

23+
TEST_TIMEOUT="-timeout 5m"
24+
2325
all: generate unit
2426

2527
###################
@@ -58,17 +60,17 @@ build:
5860

5961
unit-no-verify:
6062
@echo "go test SDK and vendor packages"
61-
go test -timeout 1m -v -count=1 -tags ${UNIT_TEST_TAGS} ${SDK_ALL_PKGS}
63+
go test ${TEST_TIMEOUT} -v -count=1 -tags ${UNIT_TEST_TAGS} ${SDK_ALL_PKGS}
6264

6365
unit: verify build unit-no-verify
6466

6567
unit-with-race-cover: verify build
6668
@echo "go test SDK and vendor packages"
67-
go test -timeout 1m -v -count=1 -tags ${UNIT_TEST_TAGS} -race -cpu=1,2,4 ${SDK_ALL_PKGS}
69+
go test ${TEST_TIMEOUT} -v -count=1 -tags ${UNIT_TEST_TAGS} -race -cpu=1,2,4 ${SDK_ALL_PKGS}
6870

6971
unit-old-go-race-cover:
7072
@echo "go test SDK only packages for old Go versions"
71-
go test -timeout 1m -v -count=1 -race -cpu=1,2,4 ${SDK_COMPA_PKGS}
73+
go test ${TEST_TIMEOUT} -v -count=1 -race -cpu=1,2,4 ${SDK_COMPA_PKGS}
7274

7375
ci-test: generate unit-with-race-cover ci-test-generate-validate
7476

aws/request/request_test.go

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/aws/aws-sdk-go/aws/awserr"
2323
"github.com/aws/aws-sdk-go/aws/client"
2424
"github.com/aws/aws-sdk-go/aws/client/metadata"
25+
"github.com/aws/aws-sdk-go/aws/corehandlers"
2526
"github.com/aws/aws-sdk-go/aws/credentials"
2627
"github.com/aws/aws-sdk-go/aws/defaults"
2728
"github.com/aws/aws-sdk-go/aws/request"
@@ -672,59 +673,47 @@ func TestWithGetResponseHeaders(t *testing.T) {
672673

673674
type testRetryer struct {
674675
shouldRetry bool
676+
maxRetries int
675677
}
676678

677679
func (d *testRetryer) MaxRetries() int {
678-
return 3
680+
return d.maxRetries
679681
}
680682

681683
// RetryRules returns the delay duration before retrying this request again
682684
func (d *testRetryer) RetryRules(r *request.Request) time.Duration {
683-
return time.Duration(time.Millisecond)
685+
return 0
684686
}
685687

686688
func (d *testRetryer) ShouldRetry(r *request.Request) bool {
687-
d.shouldRetry = true
688-
if r.Retryable != nil {
689-
return *r.Retryable
690-
}
691-
692-
if r.HTTPResponse.StatusCode >= 500 {
693-
return true
694-
}
695-
return r.IsErrorRetryable()
689+
return d.shouldRetry
696690
}
697691

698692
func TestEnforceShouldRetryCheck(t *testing.T) {
699-
tp := &http.Transport{
700-
Proxy: http.ProxyFromEnvironment,
701-
ResponseHeaderTimeout: 1 * time.Millisecond,
702-
}
703-
704-
client := &http.Client{Transport: tp}
705-
706-
testDone := make(chan struct{})
707-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
708-
// This server should wait forever. Requests will timeout and the SDK should
709-
// attempt to retry.
710-
select {
711-
case <-testDone:
712-
}
713-
}))
714-
defer server.Close()
715693

716-
retryer := &testRetryer{}
694+
retryer := &testRetryer{
695+
shouldRetry: true, maxRetries: 3,
696+
}
717697
s := awstesting.NewClient(&aws.Config{
718698
Region: aws.String("mock-region"),
719699
MaxRetries: aws.Int(0),
720-
Endpoint: aws.String(server.URL),
721-
DisableSSL: aws.Bool(true),
722700
Retryer: retryer,
723-
HTTPClient: client,
724701
EnforceShouldRetryCheck: aws.Bool(true),
702+
SleepDelay: func(time.Duration) {},
725703
})
726704

727705
s.Handlers.Validate.Clear()
706+
s.Handlers.Send.Swap(corehandlers.SendHandler.Name, request.NamedHandler{
707+
Name: "TestEnforceShouldRetryCheck",
708+
Fn: func(r *request.Request) {
709+
r.HTTPResponse = &http.Response{
710+
Header: http.Header{},
711+
Body: ioutil.NopCloser(bytes.NewBuffer(nil)),
712+
}
713+
r.Retryable = aws.Bool(false)
714+
},
715+
})
716+
728717
s.Handlers.Unmarshal.PushBack(unmarshal)
729718
s.Handlers.UnmarshalError.PushBack(unmarshalError)
730719

@@ -740,8 +729,6 @@ func TestEnforceShouldRetryCheck(t *testing.T) {
740729
if !retryer.shouldRetry {
741730
t.Errorf("expect 'true' for ShouldRetry, but got %v", retryer.shouldRetry)
742731
}
743-
744-
close(testDone)
745732
}
746733

747734
type errReader struct {

0 commit comments

Comments
 (0)