27
27
class TestAsyncCancellation (AsyncIntegrationTest ):
28
28
async def test_async_cancellation_closes_connection (self ):
29
29
pool = await async_get_pool (self .client )
30
- await connected (self .client )
31
- conn = one (pool .conns )
32
30
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 )
34
34
35
35
async def task ():
36
36
await self .client .db .test .find_one ({"$where" : delay (0.2 )})
@@ -47,9 +47,8 @@ async def task():
47
47
48
48
@async_client_context .require_transactions
49
49
async def test_async_cancellation_aborts_transaction (self ):
50
- await connected (self .client )
51
50
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 , {} )
53
52
54
53
session = self .client .start_session ()
55
54
@@ -71,10 +70,8 @@ async def task():
71
70
72
71
@async_client_context .require_failCommand_blockConnection
73
72
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 , {})
78
75
79
76
cursor = self .client .db .test .find ({}, batch_size = 1 )
80
77
await cursor .next ()
@@ -103,9 +100,7 @@ async def task():
103
100
@async_client_context .require_change_streams
104
101
@async_client_context .require_failCommand_blockConnection
105
102
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 , {})
109
104
change_stream = await self .client .db .test .watch (batch_size = 2 )
110
105
111
106
# Make sure getMore commands block
@@ -117,8 +112,7 @@ async def test_async_cancellation_closes_change_stream(self):
117
112
118
113
async def task ():
119
114
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 }])
122
116
await change_stream .next ()
123
117
124
118
task = asyncio .create_task (task ())
0 commit comments