MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / test_pool_exception_in_setup_and_init

Method test_pool_exception_in_setup_and_init

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

Source from the content-addressed store, hash-verified

317 self.assertIsInstance(pool, asyncpg.pool.Pool)
318
319 async def test_pool_exception_in_setup_and_init(self):
320 class Error(Exception):
321 pass
322
323 async def setup(con):
324 nonlocal setup_calls, last_con
325 last_con = con
326 setup_calls += 1
327 if setup_calls > 1:
328 cons.append(con)
329 else:
330 cons.append('error')
331 raise Error
332
333 with self.subTest(method='setup'):
334 setup_calls = 0
335 last_con = None
336 cons = []
337 async with self.create_pool(database='postgres',
338 min_size=1, max_size=1,
339 setup=setup) as pool:
340 with self.assertRaises(Error):
341 await pool.acquire()
342 self.assertTrue(last_con.is_closed())
343
344 async with pool.acquire() as con:
345 self.assertEqual(cons, ['error', con])
346
347 with self.subTest(method='init'):
348 setup_calls = 0
349 last_con = None
350 cons = []
351 async with self.create_pool(database='postgres',
352 min_size=0, max_size=1,
353 init=setup) as pool:
354 with self.assertRaises(Error):
355 await pool.acquire()
356 self.assertTrue(last_con.is_closed())
357
358 async with pool.acquire() as con:
359 self.assertEqual(await con.fetchval('select 1::int'), 1)
360 self.assertEqual(cons, ['error', con._con])
361
362 async def test_pool_auth(self):
363 if not self.cluster.is_managed():

Callers

nothing calls this directly

Calls 4

is_closedMethod · 0.80
create_poolMethod · 0.45
acquireMethod · 0.45
fetchvalMethod · 0.45

Tested by

no test coverage detected