Skip to content

Commit 847cf9c

Browse files
committed
add 2 test cases
1 parent bdcd96e commit 847cf9c

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

python-sdk-functional-test/retry_test.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,38 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from mock import MagicMock, patch
1516
from base import SDKTestBase
17+
from aliyunsdkcore.client import AcsClient
18+
from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
19+
from aliyunsdkcore.acs_exception.exceptions import ClientException
20+
import aliyunsdkcore.acs_exception.error_code as error_code
1621

1722

1823
class RetryTest(SDKTestBase):
1924

20-
pass
25+
def test_no_retry(self):
26+
27+
client = AcsClient(self.access_key_id, self.access_key_secret, self.region_id,
28+
auto_retry=False)
29+
request = DescribeInstancesRequest()
30+
request.set_endpoint("somewhere.you.will.never.get")
31+
with patch.object(client, "_handle_single_request") as monkey:
32+
try:
33+
client.do_action_with_exception(request)
34+
assert False
35+
except ClientException as e:
36+
self.assertEqual(error_code.SDK_HTTP_ERROR, e.get_error_code())
37+
self.assertEqual(1, monkey.call_count)
38+
39+
def test_default_retry(self):
40+
client = AcsClient(self.access_key_id, self.access_key_secret, self.region_id)
41+
request = DescribeInstancesRequest()
42+
request.set_endpoint("somewhere.you.will.never.get")
43+
with patch.object(client, "_handle_single_request") as monkey:
44+
try:
45+
client.do_action_with_exception(request)
46+
assert False
47+
except ClientException as e:
48+
self.assertEqual(error_code.SDK_HTTP_ERROR, e.get_error_code())
49+
self.assertEqual(4, monkey.call_count)

0 commit comments

Comments
 (0)