-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5080 - Convert test.test_examples to async #2097
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
Conversation
|
The remaining failure is |
test/test_examples.py
Outdated
| db = self.db | ||
|
|
||
| # Start Aggregation Example 1 | ||
|
|
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.
doesn't matter that much, but new line?
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.
Good catch!
| session=s, | ||
| ) | ||
| ).next() | ||
| )["adoptableCatsCount"] |
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.
Is this really ruff's formatting? Ew.
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.
Yeah it's not great.
test/test_examples.py
Outdated
| db.inventory.insert_one({"username": "alice"}) | ||
| db.inventory.delete_one({"username": "alice"}) | ||
|
|
||
| t = asyncio.create_task(insert_docs()) |
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.
Could we utilize a Thread/Task wrapper api to avoid duplicating tests like this? For example, like ExceptionCatchingTask/ExceptionCatchingThread.
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.
Similar to how SpecRunnerThread/SpecRunnerTask work? We could move that abstraction up to be a generic class we use everywhere we need a similar pattern.
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.
Updated #2094 for this use case.
test/asynchronous/helpers.py
Outdated
| if self.args: | ||
| await self.target(*self.args) | ||
| else: | ||
| await self.target() |
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.
await self.target(*self.args) will work even if self.args is an empty list so this code can be simplified.
test/asynchronous/helpers.py
Outdated
| return not self.stopped | ||
|
|
||
| async def run(self): | ||
| if self.target: |
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.
When would "target" ever be None?
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.
Good point, we'd want it to throw an error here instead of being a silent no-op.
| nonlocal done | ||
| while not done: | ||
| db.inventory.insert_one({"username": "alice"}) | ||
| db.inventory.delete_one({"username": "alice"}) |
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.
We should probably put a short sleep in here (5ms maybe) to avoid a tight loop.
ShaneHarvey
left a comment
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.
Sorry one last question.
test/asynchronous/helpers.py
Outdated
| if self.target: | ||
| await self.target() | ||
| await self.target(*self.args) | ||
| self.stopped = True |
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.
Do we need to set stopped to try even when target raises? If so I suggest using try/finally.
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.
Good point, I'd say so.
No description provided.