2727class TestAsyncCancellation (AsyncIntegrationTest ):
2828 async def test_async_cancellation_closes_connection (self ):
2929 pool = await async_get_pool (self .client )
30- await connected (self .client )
31- conn = one (pool .conns )
3230 await self .client .db .test .insert_one ({"x" : 1 })
33- self .addAsyncCleanup (self .client .db .test .drop )
31+ self .addAsyncCleanup (self .client .db .test .delete_many , {})
32+
33+ conn = one (pool .conns )
3434
3535 async def task ():
3636 await self .client .db .test .find_one ({"$where" : delay (0.2 )})
@@ -47,9 +47,8 @@ async def task():
4747
4848 @async_client_context .require_transactions
4949 async def test_async_cancellation_aborts_transaction (self ):
50- await connected (self .client )
5150 await self .client .db .test .insert_one ({"x" : 1 })
52- self .addAsyncCleanup (self .client .db .test .drop )
51+ self .addAsyncCleanup (self .client .db .test .delete_many , {} )
5352
5453 session = self .client .start_session ()
5554
@@ -71,10 +70,8 @@ async def task():
7170
7271 @async_client_context .require_failCommand_blockConnection
7372 async def test_async_cancellation_closes_cursor (self ):
74- await connected (self .client )
75- for _ in range (2 ):
76- await self .client .db .test .insert_one ({"x" : 1 })
77- self .addAsyncCleanup (self .client .db .test .drop )
73+ await self .client .db .test .insert_many ([{"x" : 1 }, {"x" : 2 }])
74+ self .addAsyncCleanup (self .client .db .test .delete_many , {})
7875
7976 cursor = self .client .db .test .find ({}, batch_size = 1 )
8077 await cursor .next ()
@@ -103,9 +100,7 @@ async def task():
103100 @async_client_context .require_change_streams
104101 @async_client_context .require_failCommand_blockConnection
105102 async def test_async_cancellation_closes_change_stream (self ):
106- await connected (self .client )
107- self .addAsyncCleanup (self .client .db .test .drop )
108-
103+ self .addAsyncCleanup (self .client .db .test .delete_many , {})
109104 change_stream = await self .client .db .test .watch (batch_size = 2 )
110105
111106 # Make sure getMore commands block
@@ -117,8 +112,7 @@ async def test_async_cancellation_closes_change_stream(self):
117112
118113 async def task ():
119114 async with self .fail_point (fail_command ):
120- for _ in range (2 ):
121- await self .client .db .test .insert_one ({"x" : 1 })
115+ await self .client .db .test .insert_many ([{"x" : 1 }, {"x" : 2 }])
122116 await change_stream .next ()
123117
124118 task = asyncio .create_task (task ())
0 commit comments