-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DAR-2161][External] Exponential backoff for external storage registr…
…ation (#856) * Added tenacity library for backoff * Exponential backoff for external storage registration * Corrected chunk_size * Update backoff parameters * Feedback * Move retrying to API call * Remove unused imports * Undid testing changes * Poetry lock * Test case
- Loading branch information
Showing
5 changed files
with
72 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,28 @@ | ||
from unittest.mock import Mock, call, patch | ||
|
||
import pytest | ||
from requests.exceptions import HTTPError | ||
from requests.models import Response | ||
from tenacity import RetryError | ||
|
||
from darwin.backend_v2 import BackendV2 | ||
|
||
|
||
class TestBackendV2: | ||
@patch("time.sleep", return_value=None) | ||
def test_register_items_retries_on_429(self, mock_sleep): | ||
mock_client = Mock() | ||
mock_response = Mock(spec=Response) | ||
mock_response.status_code = 429 | ||
mock_client._post_raw.side_effect = HTTPError(response=mock_response) | ||
|
||
backend = BackendV2(mock_client, "team_slug") | ||
|
||
payload = {"key": "value"} | ||
with pytest.raises(RetryError): | ||
backend.register_items(payload) | ||
|
||
assert mock_client._post_raw.call_count == 10 | ||
|
||
expected_call = call("/v2/teams/team_slug/items/register_existing", payload) | ||
assert mock_client._post_raw.call_args_list == [expected_call] * 10 |
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