-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reports streams rate limit handling logics.
Add rate limit unit tests.
- Loading branch information
Showing
3 changed files
with
98 additions
and
31 deletions.
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
81 changes: 81 additions & 0 deletions
81
...ons/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py
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,81 @@ | ||
# | ||
# MIT License | ||
# | ||
# Copyright (c) 2020 Airbyte | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
# | ||
|
||
import pytest | ||
import requests | ||
from airbyte_cdk.sources.streams.http.auth import NoAuth | ||
from airbyte_cdk.sources.streams.http.exceptions import DefaultBackoffException | ||
from source_amazon_seller_partner.auth import AWSSignature | ||
from source_amazon_seller_partner.streams import MerchantListingsReports | ||
|
||
|
||
@pytest.fixture | ||
def reports_stream(): | ||
aws_signature = AWSSignature( | ||
service="execute-api", | ||
aws_access_key_id="AccessKeyId", | ||
aws_secret_access_key="SecretAccessKey", | ||
aws_session_token="SessionToken", | ||
region="US", | ||
) | ||
stream = MerchantListingsReports( | ||
url_base="https://test.url", | ||
aws_signature=aws_signature, | ||
replication_start_date="2017-01-25T00:00:00Z", | ||
marketplace_ids=["id"], | ||
authenticator=NoAuth(), | ||
) | ||
return stream | ||
|
||
|
||
def test_reports_stream_should_retry(mocker, reports_stream): | ||
response = requests.Response() | ||
response.status_code = 429 | ||
mocker.patch.object(requests.Session, "send", return_value=response) | ||
should_retry = reports_stream.should_retry(response=response) | ||
|
||
assert should_retry is True | ||
|
||
|
||
def test_reports_stream_send_request(mocker, reports_stream): | ||
response = requests.Response() | ||
response.status_code = 200 | ||
mocker.patch.object(requests.Session, "send", return_value=response) | ||
|
||
assert response == reports_stream._send_request(request=requests.PreparedRequest()) | ||
|
||
|
||
def test_reports_stream_send_request_backoff_exception(mocker, caplog, reports_stream): | ||
This comment has been minimized.
Sorry, something went wrong. |
||
response = requests.Response() | ||
response.status_code = 429 | ||
mocker.patch.object(requests.Session, "send", return_value=response) | ||
|
||
with pytest.raises(DefaultBackoffException): | ||
reports_stream._send_request(request=requests.PreparedRequest()) | ||
|
||
assert "Backing off _send_request(...) for 5.0s" in caplog.text | ||
assert "Backing off _send_request(...) for 10.0s" in caplog.text | ||
assert "Backing off _send_request(...) for 20.0s" in caplog.text | ||
assert "Backing off _send_request(...) for 40.0s" in caplog.text | ||
assert "Giving up _send_request(...) after 5 tries" in caplog.text |
27 changes: 0 additions & 27 deletions
27
airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/unit_test.py
This file was deleted.
Oops, something went wrong.
we should override
time.sleep
to make it a no-op so we don't wait 1min for this to sleep (we should also do that in the CDK tests - can you create an issue?)