-
Notifications
You must be signed in to change notification settings - Fork 77
[HZ-5415] Asyncio cancellation tests #821
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
+85
−13
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b36cdd7
added cancel test
yuce 54d6073
Merge branch 'master' into asyncio-cancellation-tests
yuce 9073478
Cancellation handling and tests
yuce b19f20a
black
yuce 26fd764
Merge branch 'master' into asyncio-cancellation-tests
yuce dcd2057
Review comments
yuce fc87e32
black
yuce 6241988
Merge branch 'master' into asyncio-cancellation-tests
yuce c00183e
Merge branch 'master' into asyncio-cancellation-tests
yuce 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
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,70 @@ | ||
| import asyncio | ||
| from asyncio import CancelledError | ||
|
|
||
| from tests.integration.asyncio.base import SingleMemberTestCase | ||
| from tests.util import random_string | ||
|
|
||
|
|
||
| class MapTest(SingleMemberTestCase): | ||
| @classmethod | ||
| def configure_client(cls, config): | ||
| config["cluster_name"] = cls.cluster.id | ||
| return config | ||
|
|
||
| async def asyncSetUp(self): | ||
| await super().asyncSetUp() | ||
| self.map = await self.client.get_map(random_string()) | ||
|
|
||
| async def asyncTearDown(self): | ||
| await self.map.destroy() | ||
| await super().asyncTearDown() | ||
|
|
||
| async def test_operation_after_cancel(self): | ||
| key = "k1" | ||
| await self.map.set(key, "v1") | ||
| task = asyncio.create_task(self.map.get(key)) | ||
| task.cancel() | ||
|
|
||
| try: | ||
| await task | ||
| except CancelledError: | ||
| pass | ||
| else: | ||
| self.fail("expected CancelledError to be raised") | ||
|
|
||
| value = await self.map.get(key) | ||
| self.assertEqual("v1", value) | ||
|
|
||
| async def test_cancel(self): | ||
| async def keep_setting(): | ||
| for i in range(1000): | ||
| await self.map.set("foo", i) | ||
| await asyncio.sleep(0) | ||
|
|
||
| task = asyncio.create_task(keep_setting()) | ||
| await asyncio.sleep(0.1) | ||
| task.cancel() | ||
| value = await self.map.get("foo") | ||
| self.assertGreater(value, 0) | ||
|
|
||
| async def test_timeout(self): | ||
| async def keep_setting(): | ||
| for i in range(1000): | ||
| await self.map.set("foo", i) | ||
| await asyncio.sleep(0) | ||
|
|
||
| try: | ||
| await asyncio.wait_for(keep_setting(), 0.1) | ||
| except TimeoutError: | ||
| pass | ||
| value = await self.map.get("foo") | ||
| self.assertGreater(value, 0) | ||
|
|
||
| async def test_complete_with_error(self): | ||
| from hazelcast.internal.asyncio_invocation import Invocation | ||
| from hazelcast.protocol.codec import client_ping_codec | ||
|
|
||
| req = client_ping_codec.encode_request() | ||
| inv = Invocation(req) | ||
| inv.future.cancel() | ||
| self.client._invocation_service._complete_with_error(inv, Exception("foo")) |
Oops, something went wrong.
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.
One thing looks interesting. Future is checked here whether canceled but not in
_complete_with_error. Does it matter?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.
Yes, updated at: dcd2057