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

Method test_pool_max_inactive_time_05

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

Source from the content-addressed store, hash-verified

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
786 # the max inactive lifetime.
787 connections = {}
788
789 async def init(con):
790 terminated = asyncio.Event()
791 connections[con] = terminated
792 con.add_termination_listener(lambda _: terminated.set())
793
794 async with self.create_pool(
795 database='postgres', init_size=2, min_size=0, max_size=2,
796 init=init,
797 max_inactive_connection_lifetime=0.2) as pool:
798
799 # A connection may expire while the remaining connections are
800 # still being initialized, so observe termination from init().
801 self.assertEqual(len(connections), 2)
802
803 await asyncio.wait_for(
804 asyncio.gather(*(event.wait()
805 for event in connections.values())),
806 timeout=5)
807
808 for con in connections:
809 self.assertTrue(con.is_closed())
810 for holder in pool._holders:
811 self.assertIsNone(holder._con)
812
813 async def test_pool_min_size_keeps_connections_alive(self):
814 # Test that min_size prevents idle connections from being closed.

Callers

nothing calls this directly

Calls 3

waitMethod · 0.80
is_closedMethod · 0.80
create_poolMethod · 0.45

Tested by

no test coverage detected