Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding 429, too many requests, to throttling error codes in default r…
…etryer
- Loading branch information
Showing
4 changed files
with
217 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
### SDK Features | ||
|
||
### SDK Enhancements | ||
`aws/client`: Adding status code 429 to throttlable status codes in default retryer (#1621) | ||
|
||
### SDK Bugs |
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,166 @@ | ||
package client | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws/request" | ||
) | ||
|
||
func TestRetryThrottleStatusCodes(t *testing.T) { | ||
cases := []struct { | ||
expectThrottle bool | ||
expectRetry bool | ||
r request.Request | ||
}{ | ||
{ | ||
false, | ||
false, | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 200}, | ||
}, | ||
}, | ||
{ | ||
true, | ||
true, | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 429}, | ||
}, | ||
}, | ||
{ | ||
true, | ||
true, | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 502}, | ||
}, | ||
}, | ||
{ | ||
true, | ||
true, | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 503}, | ||
}, | ||
}, | ||
{ | ||
true, | ||
true, | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 504}, | ||
}, | ||
}, | ||
{ | ||
false, | ||
true, | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 500}, | ||
}, | ||
}, | ||
} | ||
|
||
d := DefaultRetryer{NumMaxRetries: 10} | ||
for i, c := range cases { | ||
throttle := d.shouldThrottle(&c.r) | ||
retry := d.ShouldRetry(&c.r) | ||
|
||
if e, a := c.expectThrottle, throttle; e != a { | ||
t.Errorf("%d: expected %v, but received %v", i, e, a) | ||
} | ||
|
||
if e, a := c.expectRetry, retry; e != a { | ||
t.Errorf("%d: expected %v, but received %v", i, e, a) | ||
} | ||
} | ||
} | ||
|
||
func TestCanUseRetryAfter(t *testing.T) { | ||
cases := []struct { | ||
r request.Request | ||
e bool | ||
}{ | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 200}, | ||
}, | ||
false, | ||
}, | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 500}, | ||
}, | ||
false, | ||
}, | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 429}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 503}, | ||
}, | ||
true, | ||
}, | ||
} | ||
|
||
for i, c := range cases { | ||
a := canUseRetryAfterHeader(&c.r) | ||
if c.e != a { | ||
t.Errorf("%d: expected %v, but received %v", i, c.e, a) | ||
} | ||
} | ||
} | ||
|
||
func TestGetRetryDelay(t *testing.T) { | ||
cases := []struct { | ||
r request.Request | ||
e time.Duration | ||
equal bool | ||
ok bool | ||
}{ | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 429, Header: http.Header{"Retry-After": []string{"3600"}}}, | ||
}, | ||
3600 * time.Second, | ||
true, | ||
true, | ||
}, | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 503, Header: http.Header{"Retry-After": []string{"120"}}}, | ||
}, | ||
120 * time.Second, | ||
true, | ||
true, | ||
}, | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 503, Header: http.Header{"Retry-After": []string{"120"}}}, | ||
}, | ||
1 * time.Second, | ||
false, | ||
true, | ||
}, | ||
{ | ||
request.Request{ | ||
HTTPResponse: &http.Response{StatusCode: 503, Header: http.Header{"Retry-After": []string{""}}}, | ||
}, | ||
0 * time.Second, | ||
true, | ||
false, | ||
}, | ||
} | ||
|
||
for i, c := range cases { | ||
a, ok := getRetryDelay(&c.r) | ||
if c.ok != ok { | ||
t.Errorf("%d: expected %v, but received %v", i, c.ok, ok) | ||
} | ||
|
||
if (c.e != a) == c.equal { | ||
t.Errorf("%d: expected %v, but received %v", i, c.e, a) | ||
} | ||
} | ||
} |
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