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

Method _test_connect_interruption

tests/test_connect.py:2145–2164  ·  view source on GitHub ↗
(self, *, ready, cancel, **conn_args)

Source from the content-addressed store, hash-verified

2143 self.loop.set_exception_handler(old_handler)
2144
2145 async def _test_connect_interruption(self, *, ready, cancel, **conn_args):
2146 async def connect():
2147 # Python 3.9 wraps CancelledError when it crosses a task boundary.
2148 # Capture the original exception so its cause can be checked.
2149 expected = (asyncio.CancelledError if cancel
2150 else asyncio.TimeoutError)
2151 with self.assertRaises(expected) as raised:
2152 await self.connect(timeout=2 if cancel else 0.2, **conn_args)
2153 return raised.exception
2154
2155 task = self.loop.create_task(connect())
2156 try:
2157 if cancel:
2158 await asyncio.wait_for(ready.wait(), 2)
2159 task.cancel()
2160 return await task
2161 finally:
2162 if not task.done():
2163 task.cancel()
2164 await asyncio.gather(task, return_exceptions=True)
2165
2166 @contextlib.asynccontextmanager
2167 async def connection_proxy(self, *faults, direct=False):

Calls 3

connectFunction · 0.85
waitMethod · 0.80
cancelMethod · 0.45

Tested by

no test coverage detected