Browse Source

brakpoint

Signed-off-by: gaort <rutong.grt@alibaba-inc.com>
gaort 7 years ago
parent
commit
a529f8a3c6
3 changed files with 13 additions and 3 deletions
  1. 1 1
      sdk/auth/signers/signer_sts_assume_role.go
  2. 8 1
      sdk/client.go
  3. 4 1
      sdk/client_test.go

+ 1 - 1
sdk/auth/signers/signer_sts_assume_role.go

@@ -67,7 +67,7 @@ func NewSignerStsAssumeRole(credential *credentials.StsRoleArnCredential, common
 		if credential.RoleSessionExpiration > 900 && credential.RoleSessionExpiration < 3600 {
 			signer.credentialExpiration = credential.RoleSessionExpiration
 		} else {
-			err = errors.NewClientError(errors.InvalidParamCode, "Assume Role session duration should be in the range of 15min - 1Hr", nil)
+			err = errors.NewClientError(errors.InvalidParamErrorCode, "Assume Role session duration should be in the range of 15min - 1Hr", nil)
 		}
 	} else {
 		signer.credentialExpiration = defaultDurationSeconds

+ 8 - 1
sdk/client.go

@@ -23,6 +23,8 @@ import (
 	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
 	"net"
 	"net/http"
+	"fmt"
+	"strconv"
 )
 
 // this value will be replaced while build: -ldflags="-X sdk.version=x.x.x"
@@ -193,8 +195,13 @@ func (client *Client) DoActionWithSigner(request requests.AcsRequest, response r
 		var timeout bool
 		// receive error
 		if err != nil {
-			// if not timeout error, return
 			if timeout = isTimeout(err); !timeout {
+				// if not timeout error, return
+				return
+			} else if retryTimes >= client.config.MaxRetryTime {
+				// timeout but reached the max retry times, return
+				timeoutErrorMsg := fmt.Sprintf(errors.TimeoutErrorMessage, strconv.Itoa(retryTimes + 1), strconv.Itoa(retryTimes + 1))
+				err = errors.NewClientError(errors.TimeoutErrorCode, timeoutErrorMsg, err)
 				return
 			}
 		}

+ 4 - 1
sdk/client_test.go

@@ -104,6 +104,9 @@ func testSetup() {
 		WithHttpTransport(&http.Transport{
 			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
 		})
+		//}).
+		//WithMaxRetryTime(15).
+		//WithTimeout(10)
 
 	credential := &credentials.BaseCredential{
 		AccessKeyId:     testConfig.AccessKeyId,
@@ -141,7 +144,7 @@ func TestRoaGet(t *testing.T) {
 
 	response := &responses.BaseResponse{}
 	err := client.DoAction(request, response)
-	assert.Nil(t, err)
+	assert.Nil(t, err, err.Error())
 	assert.Equal(t, http.StatusOK, response.GetHttpStatus(), response.GetHttpContentString())
 	assert.NotNil(t, response.GetHttpContentString())