-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PYTHON-5081 Convert test.test_gridfs to async #2099
Conversation
gridfs/asynchronous/grid_file.py
Outdated
@@ -231,7 +231,7 @@ async def get_version( | |||
try: | |||
doc = await anext(cursor) | |||
return AsyncGridOut(self._collection, file_document=doc, session=session) | |||
except StopIteration: | |||
except (StopIteration, StopAsyncIteration): |
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.
except (StopIteration, StopAsyncIteration): | |
except StopAsyncIteration: |
The asynchronous API should only throw StopAsyncIteration, and the synchronous API should only throw StopIteration.
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.
oh yeah, that makes sense HAHA silly me
test/asynchronous/test_gridfs.py
Outdated
assert data == b"hello" | ||
else: | ||
|
||
class JustWrite(asyncio.Task): |
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 don't want to subclass Task
, but have the async JustWrite
class have a self.task
instance.
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.
oh right, that's what we said today in OH just changed it :)
test/asynchronous/test_gridfs.py
Outdated
self.n = n | ||
self.daemon = True | ||
|
||
class JustRead(asyncio.Task): |
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.
Same here.
test/asynchronous/test_gridfs.py
Outdated
|
||
class JustWrite: | ||
def __init__(self, fs, n): | ||
async def run(): |
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.
This should be a separate method, not nested inside __init__
.
test/asynchronous/test_gridfs.py
Outdated
|
||
class JustRead: | ||
def __init__(self, fs, n, results): | ||
async def run(): |
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.
Same here.
test/utils.py
Outdated
async def asyncjoinall(tasks): | ||
"""Join tasks with a 5-minute timeout, assert joins succeeded""" | ||
for t in tasks: | ||
await asyncio.wait_for(t.task, 300) |
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 asyncio.wait_for(t.task, 300) | |
await asyncio.wait([t.task], timeout=300) |
wait_for
will throw a TimeoutError
if it times out, wait
will just return the task that didn't complete.
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.
ahh i didn't know that!
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.
LGTM pending Shane's review.
test/utils.py
Outdated
async def asyncjoinall(tasks): | ||
"""Join tasks with a 5-minute timeout, assert joins succeeded""" | ||
for t in tasks: | ||
await asyncio.wait([t.task], timeout=300) |
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 use gather() to join all tasks at 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.
Better yet, use asyncio.wait
.
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 idea! done!
test/test_gridfs.py
Outdated
|
||
if _IS_SYNC: | ||
|
||
class JustWrite(threading.Thread): |
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.
Can we use the shared thread/task api that Noah introduced here?
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! Just changed that!
test/asynchronous/test_gridfs.py
Outdated
if _IS_SYNC: | ||
joinall(tasks) | ||
else: | ||
await asyncio.wait([t.task for t in tasks if t.task is not 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.
Let's put this logic into an async_joinall
method to avoid this branch. Also, there should be a 5-minute timeout on this wait to match joinall
.
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.
makes sense, done!
test/asynchronous/test_gridfs.py
Outdated
if _IS_SYNC: | ||
joinall(tasks) | ||
else: | ||
await asyncio.wait([t.task for t in tasks if t.task is not 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.
Same here.
"test_load_balancer.py", | ||
"test_json_util_integration.py", | ||
"test_gridfs_spec.py", | ||
"test_json_util_integration.py", |
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.
test_json_util_integration is duplicated here.
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.
nice catch, sorry for missing that!
No description provided.