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

Method test_pool_max_inactive_time_04

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

Source from the content-addressed store, hash-verified

686 self.assertIs(pool._holders[0]._con, con)
687
688 async def test_pool_max_inactive_time_04(self):
689 # Chaos test for max_inactive_connection_lifetime.
690 DURATION = 2.0
691 START = time.monotonic()
692 N = 0
693
694 async def worker(pool):
695 nonlocal N
696 await asyncio.sleep(random.random() / 10 + 0.1)
697 async with pool.acquire() as con:
698 if random.random() > 0.5:
699 await con.execute('SELECT pg_sleep({:.2f})'.format(
700 random.random() / 10))
701 self.assertEqual(
702 await con.fetchval('SELECT 42::int'),
703 42)
704
705 if time.monotonic() - START < DURATION:
706 await worker(pool)
707
708 N += 1
709
710 async with self.create_pool(
711 database='postgres', min_size=10, max_size=30,
712 max_inactive_connection_lifetime=0.1) as pool:
713
714 workers = [worker(pool) for _ in range(50)]
715 await asyncio.gather(*workers)
716
717 self.assertGreaterEqual(N, 50)
718
719 async def test_pool_max_inactive_time_05(self):
720 # Test that idle never-acquired connections abide by

Callers

nothing calls this directly

Calls 1

create_poolMethod · 0.45

Tested by

no test coverage detected