Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDL-22608 update backoff conditions #19

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## 1.0.1
* 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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 7 additions & 4 deletions tap_sailthru/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
39 changes: 37 additions & 2 deletions tests/unittests/test_error_handling.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from unittest import mock
import tap_sailthru.client as client
import unittest
import requests
from unittest import mock
from http.client import RemoteDisconnected
import tap_sailthru.client as client

# mocked response class
class Mockresponse:
Expand Down Expand Up @@ -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)