-
Notifications
You must be signed in to change notification settings - Fork 90
Implement wait_for_pending_update method #79
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c502a34
Implement wait_for_pending_update method
eskombro 7a51285
Apply suggestions from code review (curquiza)
eskombro 8865df5
Clarify comments on wait_for_pending_update method
eskombro 8784be9
Add test with interval set to 0
eskombro 0e1b016
Lint
eskombro b8e720f
Default values set to 5000 (timeout_in_ms) and 50 (interval_in_ms)
eskombro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,61 @@ | ||
from datetime import datetime | ||
import json | ||
import pytest | ||
import meilisearch | ||
from meilisearch.tests import BASE_URL, MASTER_KEY | ||
|
||
class TestUpdate: | ||
client = meilisearch.Client(BASE_URL, MASTER_KEY) | ||
index = None | ||
dataset_file = open("datasets/small_movies.json", "r") | ||
dataset_json = None | ||
|
||
def setup_class(self): | ||
self.index = self.client.create_index(uid='indexUID') | ||
self.dataset_json = json.loads(self.dataset_file.read()) | ||
|
||
def teardown_class(self): | ||
self.index.delete() | ||
|
||
def test_wait_for_pending_update_default(self): | ||
"""Tests call to wait for an update with default parameters""" | ||
response = self.index.add_documents([{'id': 1, 'title': 'Le Petit Prince'}]) | ||
assert 'updateId' in response | ||
wait_update = self.index.wait_for_pending_update(response['updateId']) | ||
assert isinstance(wait_update, object) | ||
assert 'status' in wait_update | ||
assert wait_update['status'] != 'enqueued' | ||
|
||
def test_wait_for_pending_update_timeout(self): | ||
"""Tests timeout risen by waiting for an update""" | ||
with pytest.raises(TimeoutError): | ||
self.index.wait_for_pending_update(2, timeout_in_ms=0) | ||
|
||
def test_wait_for_pending_update_interval_custom(self): | ||
"""Tests call to wait for an update with custom interval""" | ||
response = self.index.add_documents(self.dataset_json) | ||
assert 'updateId' in response | ||
start_time = datetime.now() | ||
wait_update = self.index.wait_for_pending_update( | ||
response['updateId'], | ||
interval_in_ms=1000, | ||
timeout_in_ms=6000 | ||
) | ||
time_delta = datetime.now() - start_time | ||
assert isinstance(wait_update, object) | ||
assert 'status' in wait_update | ||
assert wait_update['status'] != 'enqueued' | ||
assert time_delta.seconds >= 1 | ||
|
||
def test_wait_for_pending_update_interval_zero(self): | ||
"""Tests call to wait for an update with custom interval""" | ||
response = self.index.add_documents(self.dataset_json) | ||
assert 'updateId' in response | ||
wait_update = self.index.wait_for_pending_update( | ||
response['updateId'], | ||
interval_in_ms=0, | ||
timeout_in_ms=6000 | ||
) | ||
assert isinstance(wait_update, object) | ||
assert 'status' in wait_update | ||
assert wait_update['status'] != 'enqueued' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What does this line do?
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.
It uses the timedelta object to calculate the number of milliseconds since the moment the user called the wait_for_pending_update method. time_delta is an instance of a timedelta object, this just converts it to an int in ms