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

Method test_pool_handles_query_cancel_in_release

tests/test_pool.py:471–490  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

469 self.assertEqual(pool._queue.qsize(), 1)
470
471 async def test_pool_handles_query_cancel_in_release(self):
472 # Use SlowResetConnectionPool to simulate
473 # the Task.cancel() and __aexit__ race.
474 pool = await self.create_pool(database='postgres',
475 init_size=1, min_size=1, max_size=1,
476 connection_class=SlowCancelConnection)
477
478 async def worker():
479 async with pool.acquire() as con:
480 await con.execute('SELECT pg_sleep(10)')
481
482 task = self.loop.create_task(worker())
483 # Let the worker() run.
484 await asyncio.sleep(0.1)
485 # Cancel the worker.
486 task.cancel()
487 # Wait to make sure the cleanup has completed.
488 await asyncio.sleep(0.5)
489 # Check that the connection has been returned to the pool.
490 self.assertEqual(pool._queue.qsize(), 1)
491
492 async def test_pool_release_timeout_during_cancellation(self):
493 pool = await self.create_pool(database='postgres',

Callers

nothing calls this directly

Calls 2

create_poolMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected