-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5089 Convert test.test_mongos_load_balancing to async #2107
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
Changes from 1 commit
ff0d5dc
690dcf7
988663f
4b8f936
5cd8be8
499fe42
41d2aab
3c7c2cb
5cd7d02
8b3f1a9
b0c878c
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 |
|---|---|---|
|
|
@@ -34,17 +34,11 @@ | |
| _IS_SYNC = False | ||
|
|
||
|
|
||
| @async_client_context.require_connection | ||
| @async_client_context.require_no_load_balancer | ||
| def asyncSetUpModule(): | ||
| pass | ||
|
|
||
|
|
||
| if not _IS_SYNC: | ||
|
|
||
| class SimpleOp: | ||
| def __init__(self, client): | ||
| self.task: asyncio.Task | ||
| self.task = asyncio.create_task(self.run()) | ||
|
||
| self.client = client | ||
| self.passed = False | ||
|
|
||
|
|
@@ -53,7 +47,7 @@ async def run(self): | |
| self.passed = True # No exception raised. | ||
|
|
||
| def start(self): | ||
| self.task = asyncio.create_task(self.run()) | ||
| pass | ||
|
|
||
| async def join(self): | ||
| await self.task | ||
|
|
@@ -70,15 +64,15 @@ def run(self): | |
| self.passed = True # No exception raised. | ||
|
|
||
|
|
||
| async def do_simple_op(client, nthreads): | ||
| threads = [SimpleOp(client) for _ in range(nthreads)] | ||
| for t in threads: | ||
| async def do_simple_op(client, ntasks): | ||
| tasks = [SimpleOp(client) for _ in range(ntasks)] | ||
| for t in tasks: | ||
| t.start() | ||
|
|
||
| for t in threads: | ||
| for t in tasks: | ||
| await t.join() | ||
|
|
||
| for t in threads: | ||
| for t in tasks: | ||
| assert t.passed | ||
|
|
||
|
|
||
|
|
@@ -90,6 +84,11 @@ async def writable_addresses(topology): | |
|
|
||
|
|
||
| class TestMongosLoadBalancing(AsyncMockClientTest): | ||
| @async_client_context.require_connection | ||
| @async_client_context.require_no_load_balancer | ||
| async def asyncSetUp(self): | ||
| await super().asyncSetUp() | ||
|
|
||
| def mock_client(self, **kwargs): | ||
| mock_client = AsyncMockClient( | ||
| standalones=[], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,17 +34,11 @@ | |
| _IS_SYNC = True | ||
|
|
||
|
|
||
| @client_context.require_connection | ||
| @client_context.require_no_load_balancer | ||
| def setUpModule(): | ||
|
Contributor
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. We can keep these to improve performance when skipping this test suite.
Contributor
Author
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 moved it to the class's
Contributor
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. Oh whoops my bad, forgot how the wrappers interact with async. You're right!
Contributor
Author
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. All good, wasn't sure if I was missing / forgetting what the trick was! |
||
| pass | ||
|
|
||
|
|
||
| if not _IS_SYNC: | ||
|
|
||
| class SimpleOp: | ||
| def __init__(self, client): | ||
| self.task: asyncio.Task | ||
| self.task = asyncio.create_task(self.run()) | ||
| self.client = client | ||
| self.passed = False | ||
|
|
||
|
|
@@ -53,7 +47,7 @@ def run(self): | |
| self.passed = True # No exception raised. | ||
|
|
||
| def start(self): | ||
| self.task = asyncio.create_task(self.run()) | ||
| pass | ||
|
|
||
| def join(self): | ||
| self.task | ||
|
|
@@ -70,15 +64,15 @@ def run(self): | |
| self.passed = True # No exception raised. | ||
|
||
|
|
||
|
|
||
| def do_simple_op(client, nthreads): | ||
| threads = [SimpleOp(client) for _ in range(nthreads)] | ||
| for t in threads: | ||
| def do_simple_op(client, ntasks): | ||
| tasks = [SimpleOp(client) for _ in range(ntasks)] | ||
| for t in tasks: | ||
| t.start() | ||
|
|
||
| for t in threads: | ||
| for t in tasks: | ||
| t.join() | ||
|
|
||
| for t in threads: | ||
| for t in tasks: | ||
| assert t.passed | ||
|
|
||
|
|
||
|
|
@@ -90,6 +84,11 @@ def writable_addresses(topology): | |
|
|
||
|
|
||
| class TestMongosLoadBalancing(MockClientTest): | ||
| @client_context.require_connection | ||
| @client_context.require_no_load_balancer | ||
| def setUp(self): | ||
| super().setUp() | ||
|
|
||
| def mock_client(self, **kwargs): | ||
| mock_client = MockClient( | ||
| standalones=[], | ||
|
|
||
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.
Let's standardize these checks to
if _IS_SYNCfor clarity.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.
Okay yes, that's what I wanted (and did initially) but for some reason if its
if _IS_SYNCfirst, type-checker assumes both definitions ofSimpleOpinherit from threading.Thread and then insist that both implementations adhere to the thread api (in this casejoinmust return a value)is that preferred? it felt weird to return a value for the sake of it in the async version of SimpleOp simply because its not used at all
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.
Our typing checks do, or the IDE's own highlighting does? Either way, we should have all checks be for
_IS_SYNCwhenever possible for clarity.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.
both, our typing checks is what caught my attention first actually