MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / pending_cancel

Method pending_cancel

tests/test_timeout.py:163–186  ·  view source on GitHub ↗
(self, *, cancel_sent, command_timeout=None)

Source from the content-addressed store, hash-verified

161
162 @contextlib.asynccontextmanager
163 async def pending_cancel(self, *, cancel_sent, command_timeout=None):
164 con = await self.connect(command_timeout=command_timeout)
165 cancel_started = asyncio.Event()
166
167 async def cancel(**kwargs):
168 cancel_started.set()
169 if not cancel_sent:
170 await self.loop.create_future()
171
172 # Exercise the actual Cython futures: either the cancel connection
173 # stalls, or it closes without the query receiving ReadyForQuery.
174 with mock.patch.object(connect_utils, '_cancel', cancel):
175 cancellations = []
176 try:
177 with self.assertRaises(asyncio.TimeoutError):
178 await con.execute('select pg_sleep(10)', timeout=0.01)
179 await cancel_started.wait()
180 cancellations = list(con._cancellations)
181 self.assertTrue(con._protocol._is_cancelling())
182 yield con
183 finally:
184 con.terminate()
185 con._transport.abort()
186 await asyncio.gather(*cancellations, return_exceptions=True)
187
188 async def test_close_times_out_pending_cancel(self):
189 for cancel_sent in (False, True):

Calls 4

waitMethod · 0.80
connectMethod · 0.45
executeMethod · 0.45
terminateMethod · 0.45

Tested by

no test coverage detected