-
Notifications
You must be signed in to change notification settings - Fork 182
Fix bug with Watch and 410 retries #227
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,15 +287,65 @@ def test_watch_with_error_event(self): | |
fake_api = Mock() | ||
fake_api.get_thing = Mock(return_value=fake_resp) | ||
|
||
w = Watch() | ||
# No events are generated when no initial resourceVersion is passed | ||
# No retry is attempted either, preventing an ApiException | ||
assert not list(w.stream(fake_api.get_thing)) | ||
Comment on lines
+291
to
+293
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the existing test case, which was not actually correct for the current version of the code with retries. Additionally, I added 2 more test cases to test both code paths that my PR is related to. |
||
|
||
fake_api.get_thing.assert_called_once_with( | ||
_preload_content=False, watch=True) | ||
fake_resp.read_chunked.assert_called_once_with(decode_content=False) | ||
fake_resp.close.assert_called_once() | ||
fake_resp.release_conn.assert_called_once() | ||
|
||
def test_watch_retries_on_error_event(self): | ||
fake_resp = Mock() | ||
fake_resp.close = Mock() | ||
fake_resp.release_conn = Mock() | ||
fake_resp.read_chunked = Mock( | ||
return_value=[ | ||
'{"type": "ERROR", "object": {"code": 410, ' | ||
'"reason": "Gone", "message": "error message"}}\n']) | ||
|
||
fake_api = Mock() | ||
fake_api.get_thing = Mock(return_value=fake_resp) | ||
|
||
w = Watch() | ||
try: | ||
for _ in w.stream(fake_api.get_thing): | ||
for _ in w.stream(fake_api.get_thing, resource_version=0): | ||
self.fail(self, "Should fail with ApiException.") | ||
except client.rest.ApiException: | ||
pass | ||
|
||
# Two calls should be expected during a retry | ||
fake_api.get_thing.assert_has_calls( | ||
[call(resource_version=0, _preload_content=False, watch=True)] * 2) | ||
fake_resp.read_chunked.assert_has_calls( | ||
[call(decode_content=False)] * 2) | ||
assert fake_resp.close.call_count == 2 | ||
assert fake_resp.release_conn.call_count == 2 | ||
|
||
def test_watch_with_error_event_and_timeout_param(self): | ||
fake_resp = Mock() | ||
fake_resp.close = Mock() | ||
fake_resp.release_conn = Mock() | ||
fake_resp.read_chunked = Mock( | ||
return_value=[ | ||
'{"type": "ERROR", "object": {"code": 410, ' | ||
'"reason": "Gone", "message": "error message"}}\n']) | ||
|
||
fake_api = Mock() | ||
fake_api.get_thing = Mock(return_value=fake_resp) | ||
|
||
w = Watch() | ||
try: | ||
for _ in w.stream(fake_api.get_thing, timeout_seconds=10): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no resource_version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For testing this code path and condition, you do not actually need to supply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
self.fail(self, "Should fail with ApiException.") | ||
except client.rest.ApiException: | ||
pass | ||
|
||
fake_api.get_thing.assert_called_once_with( | ||
_preload_content=False, watch=True) | ||
_preload_content=False, watch=True, timeout_seconds=10) | ||
fake_resp.read_chunked.assert_called_once_with(decode_content=False) | ||
fake_resp.close.assert_called_once() | ||
fake_resp.release_conn.assert_called_once() | ||
|
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.
please add a comment about the added condition "not disable_retries and not"
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.
Done, see lines 154-155 as well