From 33823cfe2ed7f526c0071ee69bc596f08f1bcff6 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Mon, 8 Jul 2024 16:52:33 -0600 Subject: [PATCH 1/4] Fixed retry logic to only retry on certain status codes --- smartystreets_python_sdk/retry_sender.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/smartystreets_python_sdk/retry_sender.py b/smartystreets_python_sdk/retry_sender.py index 6521579..519d049 100644 --- a/smartystreets_python_sdk/retry_sender.py +++ b/smartystreets_python_sdk/retry_sender.py @@ -5,20 +5,19 @@ class RetrySender: MAX_BACKOFF_DURATION = 10 - STATUS_OK = 200 TOO_MANY_REQUESTS = 429 + STATUS_TO_RETRY = [408, 500, 502, 503, 504] + def __init__(self, max_retries, inner): self.inner = inner self.max_retries = max_retries def send(self, request): + standard_retry = False response = self.inner.send(request) for i in range(self.max_retries): - if response.status_code == RetrySender.STATUS_OK: - break - if response.status_code == RetrySender.TOO_MANY_REQUESTS: backoff_seconds = 10 retry_after = response.getHeader("Retry-After") @@ -27,8 +26,10 @@ def send(self, request): backoff_seconds = int(retry_after) backoff(backoff_seconds, True) - else: + elif response.status_code in RetrySender.STATUS_TO_RETRY: backoff(i) + else: + break response = self.inner.send(request) From 0efdb34385c6d8e556d183013f24fb503ee76076 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Mon, 8 Jul 2024 16:55:28 -0600 Subject: [PATCH 2/4] removed erroneous variable --- smartystreets_python_sdk/retry_sender.py | 1 - 1 file changed, 1 deletion(-) diff --git a/smartystreets_python_sdk/retry_sender.py b/smartystreets_python_sdk/retry_sender.py index 519d049..bf547a3 100644 --- a/smartystreets_python_sdk/retry_sender.py +++ b/smartystreets_python_sdk/retry_sender.py @@ -14,7 +14,6 @@ def __init__(self, max_retries, inner): self.max_retries = max_retries def send(self, request): - standard_retry = False response = self.inner.send(request) for i in range(self.max_retries): From 2dc83ff67bcf8c9cbe6de61c325f60fe1b90ae22 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Tue, 9 Jul 2024 10:14:09 -0600 Subject: [PATCH 3/4] Modified retry sender test to reflect new retry logic --- test/retry_sender_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/retry_sender_test.py b/test/retry_sender_test.py index c33708c..2bc9c4d 100644 --- a/test/retry_sender_test.py +++ b/test/retry_sender_test.py @@ -24,7 +24,7 @@ def test_success_does_not_retry(self, mocked): @patch('smartystreets_python_sdk.retry_sender.backoff', side_effect=mock_backoff) def test_retry_until_success(self, mocked): - inner = FailingSender([401, 402, 400, 200, 500]) + inner = FailingSender([408, 500, 502, 200, 504]) send_with_retry(10, inner) @@ -43,7 +43,7 @@ def test_return_response_if_retry_limit_exceeded(self, mocked): @patch('smartystreets_python_sdk.retry_sender.backoff', side_effect=mock_backoff) def test_backoff_does_not_exceed_max(self, mocked): - inner = FailingSender([401, 402, 400, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 200]) + inner = FailingSender([408, 408, 408, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 200]) send_with_retry(20, inner) From 7296c520473aeba5e75b03ea3d680567297e37ab Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Tue, 9 Jul 2024 10:17:18 -0600 Subject: [PATCH 4/4] Added new test to retry sender test --- test/retry_sender_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/retry_sender_test.py b/test/retry_sender_test.py index 2bc9c4d..2156026 100644 --- a/test/retry_sender_test.py +++ b/test/retry_sender_test.py @@ -22,6 +22,14 @@ def test_success_does_not_retry(self, mocked): self.assertEqual(1, inner.current_status_code_index) + @patch('smartystreets_python_sdk.retry_sender.backoff', side_effect=mock_backoff) + def test_payment_required_does_not_retry(self, mocked): + inner = FailingSender([402]) + + send_with_retry(5, inner) + + self.assertEqual(1, inner.current_status_code_index) + @patch('smartystreets_python_sdk.retry_sender.backoff', side_effect=mock_backoff) def test_retry_until_success(self, mocked): inner = FailingSender([408, 500, 502, 200, 504])