🐛Source Github: remove BAD_GATEWAY code from backoff_time (#9999)
* remove BAD_GATEWAY code from backoff_time * bump version * bump version * add unit test * bump version
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#
|
||||
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -15,23 +16,11 @@ DEFAULT_BACKOFF_DELAYS = [5, 10, 20, 40, 80]
|
||||
|
||||
@responses.activate
|
||||
@patch("time.sleep")
|
||||
def test_bad_gateway_retry(time_mock):
|
||||
def test_internal_server_error_retry(time_mock):
|
||||
args = {"authenticator": None, "repositories": ["test_repo"], "start_date": "start_date", "page_size_for_large_streams": 30}
|
||||
stream = PullRequestCommentReactions(**args)
|
||||
stream_slice = {"repository": "test_repo", "id": "id"}
|
||||
|
||||
responses.add(
|
||||
"GET",
|
||||
"https://api.github.com/repos/test_repo/pulls/comments/id/reactions",
|
||||
status=HTTPStatus.BAD_GATEWAY,
|
||||
json={"message": "Bad request"},
|
||||
)
|
||||
with pytest.raises(BaseBackoffException):
|
||||
list(stream.read_records(sync_mode="full_refresh", stream_slice=stream_slice))
|
||||
|
||||
sleep_delays = [delay[0][0] for delay in time_mock.call_args_list]
|
||||
assert sleep_delays == DEFAULT_BACKOFF_DELAYS
|
||||
|
||||
time_mock.reset_mock()
|
||||
responses.add(
|
||||
"GET",
|
||||
@@ -44,3 +33,18 @@ def test_bad_gateway_retry(time_mock):
|
||||
|
||||
sleep_delays = [delay[0][0] for delay in time_mock.call_args_list]
|
||||
assert sleep_delays == DEFAULT_BACKOFF_DELAYS
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("http_status", "response_text", "expected_backoff_time"),
|
||||
[
|
||||
(HTTPStatus.BAD_GATEWAY, "", 60),
|
||||
],
|
||||
)
|
||||
def test_backoff_time(http_status, response_text, expected_backoff_time):
|
||||
response_mock = MagicMock()
|
||||
response_mock.status_code = http_status
|
||||
response_mock.text = response_text
|
||||
args = {"authenticator": None, "repositories": ["test_repo"], "start_date": "start_date", "page_size_for_large_streams": 30}
|
||||
stream = PullRequestCommentReactions(**args)
|
||||
assert stream.backoff_time(response_mock) == expected_backoff_time
|
||||
|
||||
Reference in New Issue
Block a user