-
Notifications
You must be signed in to change notification settings - Fork 47
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 17878 implement request timeout and retry #126
Merged
namrata270998
merged 8 commits into
crest-master
from
TDL-17878-implement-request-timeout-and-retry
May 27, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4152e24
added configurable request timeout with default as 5 minutes
namrata270998 59941d7
added comments
namrata270998 ca8030e
Merge branch 'crest-master' of https://github.com/singer-io/tap-strip…
namrata270998 199325e
added schema missing fields missing from schema
namrata270998 6002004
fixed cci error
namrata270998 cb87c4a
added timeout in readme
namrata270998 de04230
Merge branch 'crest-master' of https://github.com/singer-io/tap-strip…
namrata270998 c77183c
Merge branch 'crest-master' of https://github.com/singer-io/tap-strip…
namrata270998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import unittest | ||
from unittest import mock | ||
from tap_stripe import Context, configure_stripe_client | ||
|
||
class TestRequestTimeoutValue(unittest.TestCase): | ||
''' | ||
Test that request timeout parameter works properly in various cases | ||
''' | ||
@mock.patch('stripe.http_client.RequestsClient') | ||
@mock.patch('tap_stripe.apply_request_timer_to_client') | ||
@mock.patch('stripe.Account.retrieve') | ||
def test_config_provided_request_timeout(self, mock_retrieve, mock_req_timer, mock_client): | ||
""" | ||
Unit tests to ensure that request timeout is set based on config value | ||
""" | ||
config = { "client_secret": "test_secret", "account_id": "test_account", "start_date": "test_start_date", "request_timeout": 100} | ||
Context.config = config | ||
configure_stripe_client() | ||
# Verify that the client is called with config provided request timeout | ||
mock_client.assert_called_with(timeout=100.0) | ||
|
||
@mock.patch('stripe.http_client.RequestsClient') | ||
@mock.patch('tap_stripe.apply_request_timer_to_client') | ||
@mock.patch('stripe.Account.retrieve') | ||
def test_default_value_request_timeout(self, mock_retrieve, mock_req_timer, mock_client): | ||
""" | ||
Unit tests to ensure that request timeout is set based default value | ||
""" | ||
config = {"client_secret": "test_secret", "account_id": "test_account", "start_date": "test_start_date"} | ||
Context.config = config | ||
configure_stripe_client() | ||
# Verify that the client is called with default request timeout | ||
mock_client.assert_called_with(timeout=300.0) | ||
|
||
@mock.patch('stripe.http_client.RequestsClient') | ||
@mock.patch('tap_stripe.apply_request_timer_to_client') | ||
@mock.patch('stripe.Account.retrieve') | ||
def test_config_provided_empty_request_timeout(self, mock_retrieve, mock_req_timer, mock_client): | ||
""" | ||
Unit tests to ensure that request timeout is set based on default value if empty value is given in config | ||
""" | ||
config = {"client_secret": "test_secret", "account_id": "test_account", "request_timeout": ""} | ||
Context.config = config | ||
configure_stripe_client() | ||
# Verify that the client is called with default request timeout | ||
mock_client.assert_called_with(timeout=300.0) | ||
|
||
@mock.patch('stripe.http_client.RequestsClient') | ||
@mock.patch('tap_stripe.apply_request_timer_to_client') | ||
@mock.patch('stripe.Account.retrieve') | ||
def test_config_provided_string_request_timeout(self, mock_retrieve, mock_req_timer, mock_client): | ||
""" | ||
Unit tests to ensure that request timeout is set based on config string value | ||
""" | ||
config = {"client_secret": "test_secret", "account_id": "test_account", "request_timeout": "100"} | ||
Context.config = config | ||
configure_stripe_client() | ||
# Verify that the client is called with config provided request timeout | ||
mock_client.assert_called_with(timeout=100.0) | ||
|
||
@mock.patch('stripe.http_client.RequestsClient') | ||
@mock.patch('tap_stripe.apply_request_timer_to_client') | ||
@mock.patch('stripe.Account.retrieve') | ||
def test_config_provided_float_request_timeout(self, mock_retrieve, mock_req_timer, mock_client): | ||
""" | ||
Unit tests to ensure that request timeout is set based on config float value | ||
""" | ||
config = {"client_secret": "test_secret", "account_id": "test_account", "request_timeout": 100.8} | ||
Context.config = config | ||
configure_stripe_client() | ||
# Verify that the client is called with config provided float request timeout | ||
mock_client.assert_called_with(timeout=100.8) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have test cases of retry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't implemented the retry logic. It is handled in the SDK itself, and the
max_network_retries
was already present in the code. Hence we have not written testcases for retry.