def test_no_retry(self):

        client = AcsClient(self.access_key_id, self.access_key_secret, self.region_id,
                           auto_retry=False)
        request = DescribeInstancesRequest()
        request.set_endpoint("somewhere.you.will.never.get")
        with patch.object(client, "_handle_single_request",
                          wraps=client._handle_single_request) as monkey:
            try:
                client.do_action_with_exception(request)
                assert False
            except ClientException as e:
                self.assertEqual(error_code.SDK_HTTP_ERROR, e.get_error_code())
        self.assertEqual(1, monkey.call_count)
    def test_set_max_retry_times(self):
        client = AcsClient(self.access_key_id,
                           self.access_key_secret,
                           self.region_id,
                           max_retry_time=8)
        request = DescribeInstancesRequest()
        request.set_endpoint("somewhere.you.will.never.get")

        def no_sleep(delay):
            pass

        with patch.object(client, "_handle_single_request",
                          wraps=client._handle_single_request) as monkey:
            with patch.object(time, "sleep", no_sleep):
                try:
                    client.do_action_with_exception(request)
                    assert False
                except ClientException as e:
                    self.assertEqual(error_code.SDK_HTTP_ERROR, e.get_error_code())
        self.assertEqual(9, monkey.call_count)
    def test_normal_backoff(self):
        client = AcsClient(self.access_key_id,
                           self.access_key_secret,
                           self.region_id,
                           max_retry_time=10)
        request = DescribeInstancesRequest()
        request.set_endpoint("somewhere.you.will.never.get")

        globals()["_test_compute_delay"] = []

        def record_sleep(delay):
            global _test_compute_delay
            _test_compute_delay.append(delay)

        with patch.object(time, "sleep", wraps=record_sleep) as monkey:
            try:
                client.do_action_with_exception(request)
                assert False
            except ClientException as e:
                self.assertEqual(error_code.SDK_HTTP_ERROR, e.get_error_code())
        self.assertEqual(10, monkey.call_count)
        self.assertEqual([0.1, 0.2, 0.4, 0.8, 1.6, 3.2, 6.4, 12.8, 20.0, 20.0],
                         _test_compute_delay)
Exemple #4
0
 def test_doc_help_sample(self):
     from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
     request = DescribeInstancesRequest()
     request.set_endpoint("ecs-cn-hangzhou.aliyuncs.com")
     response = self.client.do_action_with_exception(request)