From d8b2d5803f0e9175d6ad70c0630c884236d270d4 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 3 Mar 2025 14:22:11 -0600 Subject: [PATCH] PYTHON-5178 Make test_async_cancellation_closes_change_stream more robust --- test/asynchronous/test_async_cancellation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/asynchronous/test_async_cancellation.py b/test/asynchronous/test_async_cancellation.py index b73c7a8084..b7fde834a2 100644 --- a/test/asynchronous/test_async_cancellation.py +++ b/test/asynchronous/test_async_cancellation.py @@ -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 = { @@ -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):