You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2021/11/03 22:38:38 UTC
[libcloud] 02/04: Add a test case for successful retry scenario
where we successfuly retry on second attempt which we previously didn't
have.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch understand-ai-intelligent-retry
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit 8940a66353ced059091bdc935291378f73711eaa
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Nov 3 22:10:02 2021 +0100
Add a test case for successful retry scenario where we successfuly retry
on second attempt which we previously didn't have.
---
libcloud/test/test_connection.py | 27 +++++++++++++++++++++++++++
libcloud/utils/retry.py | 3 +--
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/libcloud/test/test_connection.py b/libcloud/test/test_connection.py
index 2848426..42ec975 100644
--- a/libcloud/test/test_connection.py
+++ b/libcloud/test/test_connection.py
@@ -470,6 +470,33 @@ class ConnectionClassTestCase(unittest.TestCase):
self.assertEqual(mock_connect.call_count, 2,
'Retry logic failed')
+ def test_retry_rate_limit_error_success_on_second_attempt(self):
+ con = Connection()
+ con.connection = Mock()
+ connect_method = 'libcloud.common.base.Connection.request'
+
+ self.retry_counter = 0
+
+ def mock_connect_side_effect(*args, **kwargs):
+ self.retry_counter += 1
+
+ if self.retry_counter < 2:
+ headers = {'retry-after': 0.2}
+ raise RateLimitReachedError(headers=headers)
+
+ return 'success'
+
+ with patch(connect_method) as mock_connect:
+ mock_connect.__name__ = 'mock_connect'
+ mock_connect.side_effect = mock_connect_side_effect
+ retry_request = Retry(timeout=0.6, retry_delay=0.1,
+ backoff=1)
+ result = retry_request(con.request)(action='/')
+ self.assertEqual(result, "success")
+
+ self.assertEqual(mock_connect.call_count, 2,
+ 'Retry logic failed')
+
class CertificateConnectionClassTestCase(unittest.TestCase):
def setUp(self):
diff --git a/libcloud/utils/retry.py b/libcloud/utils/retry.py
index a112318..baa6c73 100644
--- a/libcloud/utils/retry.py
+++ b/libcloud/utils/retry.py
@@ -119,8 +119,7 @@ class MinimalRetry:
time.sleep(current_delay)
current_delay *= self.backoff
- if last_exc and datetime.now() >= end:
- raise last_exc
+ raise last_exc
return retry_loop