2626
2727class TestAsyncCancellation (AsyncIntegrationTest ):
2828 async def test_async_cancellation_closes_connection (self ):
29- client = await self .async_rs_or_single_client (maxPoolSize = 1 )
30- pool = await async_get_pool (client )
31- await connected (client )
29+ pool = await async_get_pool (self .client )
30+ await connected (self .client )
3231 conn = one (pool .conns )
33- await client .db .test .insert_one ({"x" : 1 })
34- self .addAsyncCleanup (client .db .test .drop )
32+ await self . client .db .test .insert_one ({"x" : 1 })
33+ self .addAsyncCleanup (self . client .db .test .drop )
3534
3635 async def task ():
37- await client .db .test .find_one ({"$where" : delay (0.2 )})
36+ await self . client .db .test .find_one ({"$where" : delay (0.2 )})
3837
3938 task = asyncio .create_task (task ())
4039
@@ -48,15 +47,14 @@ async def task():
4847
4948 @async_client_context .require_transactions
5049 async def test_async_cancellation_aborts_transaction (self ):
51- client = await self .async_rs_or_single_client ()
52- await connected (client )
53- await client .db .test .insert_one ({"x" : 1 })
54- self .addAsyncCleanup (client .db .test .drop )
50+ await connected (self .client )
51+ await self .client .db .test .insert_one ({"x" : 1 })
52+ self .addAsyncCleanup (self .client .db .test .drop )
5553
56- session = client .start_session ()
54+ session = self . client .start_session ()
5755
5856 async def callback (session ):
59- await client .db .test .find_one ({"$where" : delay (0.2 )}, session = session )
57+ await self . client .db .test .find_one ({"$where" : delay (0.2 )}, session = session )
6058
6159 async def task ():
6260 await session .with_transaction (callback )
@@ -73,13 +71,12 @@ async def task():
7371
7472 @async_client_context .require_failCommand_blockConnection
7573 async def test_async_cancellation_closes_cursor (self ):
76- client = await self .async_rs_or_single_client ()
77- await connected (client )
74+ await connected (self .client )
7875 for _ in range (2 ):
79- await client .db .test .insert_one ({"x" : 1 })
80- self .addAsyncCleanup (client .db .test .drop )
76+ await self . client .db .test .insert_one ({"x" : 1 })
77+ self .addAsyncCleanup (self . client .db .test .drop )
8178
82- cursor = client .db .test .find ({}, batch_size = 1 )
79+ cursor = self . client .db .test .find ({}, batch_size = 1 )
8380 await cursor .next ()
8481
8582 # Make sure getMore commands block
@@ -106,11 +103,10 @@ async def task():
106103 @async_client_context .require_change_streams
107104 @async_client_context .require_failCommand_blockConnection
108105 async def test_async_cancellation_closes_change_stream (self ):
109- client = await self .async_rs_or_single_client ()
110- await connected (client )
111- self .addAsyncCleanup (client .db .test .drop )
106+ await connected (self .client )
107+ self .addAsyncCleanup (self .client .db .test .drop )
112108
113- change_stream = await client .db .test .watch (batch_size = 2 )
109+ change_stream = await self . client .db .test .watch (batch_size = 2 )
114110
115111 # Make sure getMore commands block
116112 fail_command = {
@@ -122,7 +118,7 @@ async def test_async_cancellation_closes_change_stream(self):
122118 async def task ():
123119 async with self .fail_point (fail_command ):
124120 for _ in range (2 ):
125- await client .db .test .insert_one ({"x" : 1 })
121+ await self . client .db .test .insert_one ({"x" : 1 })
126122 await change_stream .next ()
127123
128124 task = asyncio .create_task (task ())
0 commit comments