Skip to content

PYTHON-5178 Make test_async_cancellation_closes_change_stream more robust #2175

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
merged 1 commit into from
Mar 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/asynchronous/test_async_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async def task():
async def test_async_cancellation_closes_change_stream(self):
self.addAsyncCleanup(self.client.db.test.delete_many, {})
change_stream = await self.client.db.test.watch(batch_size=2)
event = asyncio.Event()

# Make sure getMore commands block
fail_command = {
Expand All @@ -113,11 +114,12 @@ async def test_async_cancellation_closes_change_stream(self):
async def task():
async with self.fail_point(fail_command):
await self.client.db.test.insert_many([{"x": 1}, {"x": 2}])
event.set()
await change_stream.next()

task = asyncio.create_task(task())

await asyncio.sleep(0.1)
await event.wait()

task.cancel()
with self.assertRaises(asyncio.CancelledError):
Expand Down
Loading