Skip to content

Commit

Permalink
add clarifying comment and negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendrixMSFT committed Dec 8, 2023
1 parent 0873a5d commit 0095beb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sdk/azcore/internal/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func RetryAfter(resp *http.Response) time.Duration {
type retryData struct {
header string
units time.Duration

// custom is used when the regular algorithm failed and is optional.
// the returned duration is used verbatim (units is not applied).
custom func(string) (time.Duration, error)
}

Expand Down
6 changes: 6 additions & 0 deletions sdk/azcore/internal/shared/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func TestRetryAfter(t *testing.T) {
resp.Header.Set(HeaderXMSRetryAfterMS, "400")
resp.Header.Set(HeaderRetryAfter, "300")
require.Equal(t, time.Duration(400)*time.Millisecond, RetryAfter(resp))
resp.Header = http.Header{}
resp.Header.Set(HeaderRetryAfterMS, "invalid")
require.Zero(t, RetryAfter(resp))
resp.Header = http.Header{}
resp.Header.Set(HeaderXMSRetryAfterMS, "invalid")
require.Zero(t, RetryAfter(resp))
}

func TestTypeOfT(t *testing.T) {
Expand Down

0 comments on commit 0095beb

Please sign in to comment.