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

Method test_pool_shutdown_cancels_floor_reconnect

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

Source from the content-addressed store, hash-verified

1131 for h in pool._holders if h.is_connected()))
1132
1133 async def test_pool_shutdown_cancels_floor_reconnect(self):
1134 for action in ('close', 'terminate'):
1135 with self.subTest(action=action):
1136 started = asyncio.Event()
1137 cancelled = asyncio.Event()
1138
1139 async def connect(*args, **kwargs):
1140 if started.is_set():
1141 self.fail('duplicate background connection attempt')
1142 if pool is not None:
1143 started.set()
1144 try:
1145 await asyncio.Future()
1146 finally:
1147 cancelled.set()
1148 return await pg_connection.connect(*args, **kwargs)
1149
1150 pool = None
1151 pool = await self.create_pool(
1152 init_size=1, min_size=1, max_size=1, connect=connect,
1153 )
1154 pool._holders[0]._con.terminate()
1155 await asyncio.wait_for(started.wait(), 5)
1156
1157 # The background connector reserves the holder, so an
1158 # acquirer must wait rather than exceed max_size.
1159 with self.assertRaises(asyncio.TimeoutError):
1160 await pool.acquire(timeout=0.05)
1161
1162 if action == 'close':
1163 await pool.close()
1164 else:
1165 pool.terminate()
1166 await asyncio.wait_for(cancelled.wait(), 5)
1167 self.assertTrue(pool.is_closing())
1168 self.assertEqual(pool.get_size(), 0)
1169
1170 async def test_pool_min_size_zero_allows_full_expiry(self):
1171 # When min_size=0, all idle connections are allowed to expire.

Callers

nothing calls this directly

Calls 7

waitMethod · 0.80
is_closingMethod · 0.80
get_sizeMethod · 0.80
create_poolMethod · 0.45
terminateMethod · 0.45
acquireMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected