-
Notifications
You must be signed in to change notification settings - Fork 38
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-15860 Implement Request Timeouts #79
Changes from 19 commits
529912c
c9dc74a
c85a98d
a8eb0e4
c9f0f1b
f996ed8
72def92
603928d
e1166c6
a64ce2b
ac716f9
2620ffd
43f73be
90b03d3
2c50697
cceb9fb
1ebd5c1
9711835
a067bb8
20c8858
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ def raise_for_error(response): | |
giveup=is_fatal) | ||
@backoff.on_exception(backoff.expo, | ||
(ConnectionError, Timeout),#As ConnectionError error and timeout error does not have attribute status_code, | ||
max_tries=10, # here we added another backoff expression. | ||
max_tries=5, # here we added another backoff expression. | ||
factor=2) | ||
def call_api(url, request_timeout, params, headers): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @prijendev I see all the calls to function CC: @dbshah1212 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this tap some of the streams using Zenpy sdk. So, to initialize sdk client we have read request_timeout in |
||
response = requests.get(url, params=params, headers=headers, timeout=request_timeout) # Pass request timeout | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
'after_cursor': 'some_cursor'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @prijendev Did we write test cases for different scenarios of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, We write test cases for different scenarios of request_timeout variable in test_request_timeout.py file. |
||
} | ||
|
||
REQUEST_TIMEOUT = 300 | ||
def mocked_get(*args, **kwargs): | ||
fake_response = requests.models.Response() | ||
fake_response.headers.update(kwargs.get('headers', {})) | ||
|
@@ -37,7 +38,7 @@ class TestBackoff(unittest.TestCase): | |
side_effect=[mocked_get(status_code=200, json=SINGLE_RESPONSE)]) | ||
def test_get_cursor_based_gets_one_page(self, mock_get, mock_sleep): | ||
responses = [response for response in http.get_cursor_based(url='some_url', | ||
access_token='some_token', request_timeout=300)] | ||
access_token='some_token', request_timeout=REQUEST_TIMEOUT)] | ||
actual_response = responses[0] | ||
self.assertDictEqual(SINGLE_RESPONSE, | ||
actual_response) | ||
|
@@ -54,7 +55,7 @@ def test_get_cursor_based_gets_one_page(self, mock_get, mock_sleep): | |
def test_get_cursor_based_can_paginate(self, mock_get, mock_sleep): | ||
responses = [response | ||
for response in http.get_cursor_based(url='some_url', | ||
access_token='some_token', request_timeout=300)] | ||
access_token='some_token', request_timeout=REQUEST_TIMEOUT)] | ||
|
||
self.assertDictEqual({"key1": "val1", **PAGINATE_RESPONSE}, | ||
responses[0]) | ||
|
@@ -79,7 +80,7 @@ def test_get_cursor_based_handles_429(self, mock_get, mock_sleep): | |
- can handle either a string or an integer for the retry header | ||
""" | ||
responses = [response for response in http.get_cursor_based(url='some_url', | ||
access_token='some_token', request_timeout=300)] | ||
access_token='some_token', request_timeout=REQUEST_TIMEOUT)] | ||
actual_response = responses[0] | ||
self.assertDictEqual({"key1": "val1", **SINGLE_RESPONSE}, | ||
actual_response) | ||
|
@@ -294,7 +295,7 @@ def test_call_api_handles_timeout_error(self,mock_get, mock_sleep): | |
pass | ||
|
||
# Verify the request retry 5 times on timeout | ||
self.assertEqual(mock_get.call_count, 10) | ||
self.assertEqual(mock_get.call_count, 5) | ||
|
||
@patch('requests.get') | ||
def test_call_api_handles_connection_error(self,mock_get, mock_sleep): | ||
|
@@ -306,5 +307,5 @@ def test_call_api_handles_connection_error(self,mock_get, mock_sleep): | |
pass | ||
|
||
# Verify the request retry 5 times on timeout | ||
self.assertEqual(mock_get.call_count, 10) | ||
self.assertEqual(mock_get.call_count, 5) | ||
|
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.
Please add details of it as it is the optional parameter.
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.
added.