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:753–782  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

751 self.assertIs(pool._holders[0]._con, con)
752
753 async def test_pool_max_inactive_time_04(self):
754 # Chaos test for max_inactive_connection_lifetime.
755 DURATION = 2.0
756 START = time.monotonic()
757 N = 0
758
759 async def worker(pool):
760 nonlocal N
761 await asyncio.sleep(random.random() / 10 + 0.1)
762 async with pool.acquire() as con:
763 if random.random() > 0.5:
764 await con.execute('SELECT pg_sleep({:.2f})'.format(
765 random.random() / 10))
766 self.assertEqual(
767 await con.fetchval('SELECT 42::int'),
768 42)
769
770 if time.monotonic() - START < DURATION:
771 await worker(pool)
772
773 N += 1
774
775 async with self.create_pool(
776 database='postgres', init_size=10, min_size=0, max_size=30,
777 max_inactive_connection_lifetime=0.1) as pool:
778
779 workers = [worker(pool) for _ in range(50)]
780 await asyncio.gather(*workers)
781
782 self.assertGreaterEqual(N, 50)
783
784 async def test_pool_max_inactive_time_05(self):
785 # 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