-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Useful error propagated to user when Marqo receives 429 (#150)
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
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,42 @@ | ||
import requests | ||
from tests.marqo_test import MarqoTestCase | ||
from marqo import _httprequests | ||
from unittest import mock | ||
from marqo.tensor_search import tensor_search | ||
from marqo.errors import ( | ||
IndexNotFoundError, TooManyRequestsError | ||
) | ||
|
||
class Test_HttpRequests(MarqoTestCase): | ||
|
||
def setUp(self) -> None: | ||
self.endpoint = self.authorized_url | ||
self.generic_header = {"Content-type": "application/json"} | ||
self.index_name_1 = "my-test-index-1" | ||
try: | ||
tensor_search.delete_index(config=self.config, index_name=self.index_name_1) | ||
except IndexNotFoundError as s: | ||
pass | ||
|
||
def test_too_many_reqs_error(self): | ||
mock_post = mock.MagicMock() | ||
mock_response = requests.Response() | ||
mock_response.status_code = 429 | ||
mock_response.json = lambda: '{"a":"b"}' | ||
mock_post.return_value = mock_response | ||
tensor_search.create_vector_index(config=self.config, index_name=self.index_name_1) | ||
|
||
@mock.patch('requests.post', mock_post) | ||
@mock.patch('marqo._httprequests.ALLOWED_OPERATIONS', {mock_post, requests.get, requests.put}) | ||
def run(): | ||
try: | ||
res = tensor_search.add_documents( | ||
config=self.config, index_name=self.index_name_1, | ||
docs=[{"some ": "doc"}], auto_refresh=True | ||
) | ||
raise AssertionError | ||
except TooManyRequestsError: | ||
pass | ||
return True | ||
assert run() | ||
|