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-19745 unittests and retrylogic for 500 exceptions #11

Merged
merged 41 commits into from
Jul 8, 2022

Conversation

rdeshmukh15
Copy link
Contributor

@rdeshmukh15 rdeshmukh15 commented Jul 6, 2022

Description of change

Covered below scenarios in Unit Test Cases :

  • All helper functions with positive and negative test case scenarios
  • Back-off is getting executed thrice or not.
  • Retry unit test cases if it working properly or not
  • Test cases for all kinds of exceptions handled
  • Validating the interval's value passed in config (Allowed values : HOUR, DAY, WEEK and MONTH)
  • Raising exception for invalid interval value.

Tap Changes:

  • Added Retry for 500 errors

Manual QA steps

Risks

Rollback steps

  • revert this branch

cngpowered and others added 30 commits June 27, 2022 12:07
…nger-io/tap-dixa into TDL-19674-bookmarking_strategy_bugfix
…inger-io/tap-dixa into TDL-19668-overlapping-timeslots_bugfix
Co-authored-by: Collin Simon <cosimon@users.noreply.github.com>
Co-authored-by: Collin Simon <cosimon@users.noreply.github.com>
@kethan1122
Copy link
Contributor

kethan1122 commented Jul 6, 2022

@rdeshmukh15 can u add Unit Tests stage in circleCI config.yml.
- run: name: 'Unit Tests' command: | source /usr/local/share/virtualenvs/tap-dixa/bin/activate pip install coverage nosetests --with-coverage --cover-erase --cover-package=tap_dixa --cover-html-dir=htmlcov tests/unittests coverage html

reference

@rdeshmukh15
Copy link
Contributor Author

@kethan1122 : Added the changes suggested in config.yaml

@rdeshmukh15 rdeshmukh15 marked this pull request as ready for review July 7, 2022 12:40
response = IncrementalStream.get_interval(self)
except InvalidInterval as e :
expected_error_message = "invalid interval provided"
assert str(e) == expected_error_message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use unittest assert methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done the changes as suggested.

Comment on lines 23 to 40
def mocked_failed_429_request(*args, **kwargs):
return Mockresponse('', 429, headers={}, raise_error=True)

@patch("time.sleep")
@patch("requests.Session.request", side_effect=mocked_failed_429_request)
class Test_Client(unittest.TestCase):

def test_too_many_requests_429_error(self, mocked_send, mocked_sleep):
client = Client(api_token="test")

try:
# Verifying if the custom exception 'DixaClient429Error' is raised on receiving status code 429
_ = client.get("https://test.com", "/test")
except DixaClient429Error: #as api_error:
pass

# Verifying the retry is happening thrice for the 429 exception
self.assertEquals(mocked_send.call_count, 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observed that we have not implemented backoff and retry for 5XX in the tap, implement that and add respective unittests as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

“rdeshmukh15” and others added 2 commits July 8, 2022 09:08
- verify exceptions for applicable http error codes
@cngpowered cngpowered changed the title Tdl 19745 unittests TDL-19745 unittests and retrylogic for 500 exceptions Jul 8, 2022
@RushiT0122
Copy link
Contributor

HTTPTimeout is not implemented, please implement it.

try:
self.client_obj.get("https://test.com", "/test")
except exceptions.DixaClientError as _:
self.assertEqual(str(_), "Server Error")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have descriptive error message for 5XX than "Server Error"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes as per suggestion.

- Exception class for 408 - httptimeout
- Error Message change for 5xx errors
Comment on lines 20 to 21
class DixaClient5xxError(DixaClientError):
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move DixaClient5xxError class to below DixaClient4xxError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rdeshmukh15 rdeshmukh15 merged commit 77b38cb into main Jul 8, 2022
@cngpowered cngpowered deleted the TDL-19745-unittests branch July 26, 2022 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants