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

Method connection_proxy

tests/test_connect.py:2167–2196  ·  view source on GitHub ↗
(self, *faults, direct=False)

Source from the content-addressed store, hash-verified

2165
2166 @contextlib.asynccontextmanager
2167 async def connection_proxy(self, *faults, direct=False):
2168 attempts = []
2169 tasks = []
2170 caller_loop = asyncio.get_running_loop()
2171
2172 async def configure():
2173 self.proxy.connection_factory = functools.partial(
2174 SSLProxyConnection, faults=faults, direct=direct,
2175 attempts=attempts, tasks=tasks, caller_loop=caller_loop)
2176
2177 async def finish():
2178 try:
2179 # Discarded transports must close without forced cleanup.
2180 results = await asyncio.wait_for(asyncio.gather(
2181 *tasks, return_exceptions=True), 2)
2182 for result in results:
2183 if isinstance(result, BaseException) and not isinstance(
2184 result, asyncio.CancelledError
2185 ):
2186 raise result
2187 finally:
2188 self.proxy.connection_factory = fuzzer.Connection
2189
2190 await asyncio.wrap_future(asyncio.run_coroutine_threadsafe(
2191 configure(), self.proxy.loop))
2192 try:
2193 yield self.proxy.listening_port, attempts
2194 finally:
2195 await asyncio.wrap_future(asyncio.run_coroutine_threadsafe(
2196 finish(), self.proxy.loop))
2197
2198
2199@unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster')

Calls

no outgoing calls

Tested by

no test coverage detected