From 91c19cfebaea5aa18feea9c6b998c69afe467acc Mon Sep 17 00:00:00 2001 From: VishalP <20889199+Vi6hal@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:46:06 +0530 Subject: [PATCH 1/4] added backoff for other http exceptions & updated unit tests --- tap_sailthru/client.py | 11 +++++--- tests/unittests/test_error_handling.py | 35 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/tap_sailthru/client.py b/tap_sailthru/client.py index 063ff30..308879b 100644 --- a/tap_sailthru/client.py +++ b/tap_sailthru/client.py @@ -7,7 +7,7 @@ import math import sys from typing import Union - +from http.client import RemoteDisconnected import backoff from requests import Session from requests.exceptions import Timeout @@ -320,10 +320,13 @@ def _build_request(self, endpoint, params, method): SailthruClient429Error, max_tries=MAX_RETRIES) @backoff.on_exception(backoff.expo, - (SailthruClientError, + (Timeout, + ConnectionError, + RemoteDisconnected, + SailthruClientError, + ConnectionResetError, SailthruServer5xxError, - SailthruClientStatsNotReadyError, - Timeout), + SailthruClientStatsNotReadyError), max_tries=MAX_RETRIES, factor=2) def _make_request(self, url, payload, method): diff --git a/tests/unittests/test_error_handling.py b/tests/unittests/test_error_handling.py index 3f5e322..6a724ed 100644 --- a/tests/unittests/test_error_handling.py +++ b/tests/unittests/test_error_handling.py @@ -1,5 +1,6 @@ from unittest import mock import tap_sailthru.client as client +from http.client import RemoteDisconnected import unittest import requests @@ -338,3 +339,37 @@ def test_200_response(self, mocked_sleep, mocked_request): # verify the mocked data is coming as expected self.assertEqual(response, response_json) + + def test_connection_error_backoff(self, mocked_sleep, mocked_request): + """ + Test case to verify error is not raise for 200 status code + """ + + mocked_request.side_effect = ConnectionResetError() + + # create sailthru client + sailthru_client = client.SailthruClient("test_api_key", "test_api_secret", "test_user_agent") + # function call + try: + response = sailthru_client._build_request("test_endpoint", {}, "GET") + except ConnectionResetError: + pass + + self.assertEqual(mocked_request.call_count, 3) + + def test_remotedisconnected_error_backoff(self, mocked_sleep, mocked_request): + """ + Test case to verify error is not raise for 200 status code + """ + + mocked_request.side_effect = RemoteDisconnected() + + # create sailthru client + sailthru_client = client.SailthruClient("test_api_key", "test_api_secret", "test_user_agent") + # function call + try: + response = sailthru_client._build_request("test_endpoint", {}, "GET") + except RemoteDisconnected: + pass + + self.assertEqual(mocked_request.call_count, 3) \ No newline at end of file From 50387ebc0def326d66318511a77771865558d83c Mon Sep 17 00:00:00 2001 From: VishalP <20889199+Vi6hal@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:47:25 +0530 Subject: [PATCH 2/4] updated setup.py and changelog --- CHANGELOG.md | 2 ++ setup.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d59d3de..6a567c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 1.0.1 + * Updated Backoff Conditions added support for ConnectionResetError(104) and RemoteDisconnected Error. ## 1.0.0 * Removed Additiona Package Dependencies [#16](https://github.com/singer-io/tap-sailthru/pull/16) diff --git a/setup.py b/setup.py index 96b703c..dab82ad 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="tap-sailthru", - version="1.0.0", + version="1.0.1", description="Singer.io tap for the SailThru API", long_description=readme, long_description_content_type='text/markdown', From 2629187e183c3f321029c101dad7b9dd64b69d30 Mon Sep 17 00:00:00 2001 From: VishalP <20889199+Vi6hal@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:49:28 +0530 Subject: [PATCH 3/4] fixed EOF --- tests/unittests/test_error_handling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/test_error_handling.py b/tests/unittests/test_error_handling.py index 6a724ed..662ed79 100644 --- a/tests/unittests/test_error_handling.py +++ b/tests/unittests/test_error_handling.py @@ -372,4 +372,4 @@ def test_remotedisconnected_error_backoff(self, mocked_sleep, mocked_request): except RemoteDisconnected: pass - self.assertEqual(mocked_request.call_count, 3) \ No newline at end of file + self.assertEqual(mocked_request.call_count, 3) From 4a9fcda984ddfba67e5357cfe9d6d06a5bbe1331 Mon Sep 17 00:00:00 2001 From: VishalP <20889199+Vi6hal@users.noreply.github.com> Date: Thu, 13 Apr 2023 12:28:37 +0530 Subject: [PATCH 4/4] fixed review comments --- CHANGELOG.md | 2 +- tests/unittests/test_error_handling.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a567c8..1a0c7d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## 1.0.1 - * Updated Backoff Conditions added support for ConnectionResetError(104) and RemoteDisconnected Error. + * Updated Backoff Conditions added support for ConnectionResetError(104) and RemoteDisconnected Error.[#19](https://github.com/singer-io/tap-sailthru/pull/19) ## 1.0.0 * Removed Additiona Package Dependencies [#16](https://github.com/singer-io/tap-sailthru/pull/16) diff --git a/tests/unittests/test_error_handling.py b/tests/unittests/test_error_handling.py index 662ed79..9bd0c03 100644 --- a/tests/unittests/test_error_handling.py +++ b/tests/unittests/test_error_handling.py @@ -1,8 +1,8 @@ -from unittest import mock -import tap_sailthru.client as client -from http.client import RemoteDisconnected import unittest import requests +from unittest import mock +from http.client import RemoteDisconnected +import tap_sailthru.client as client # mocked response class class Mockresponse: