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

Method test_pool_connection_methods

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

Source from the content-addressed store, hash-verified

606 self.assertNotEqual(id2, id3)
607
608 async def test_pool_connection_methods(self):
609 async def test_fetch(pool):
610 i = random.randint(0, 20)
611 await asyncio.sleep(random.random() / 100)
612 r = await pool.fetch('SELECT {}::int'.format(i))
613 self.assertEqual(r, [(i,)])
614 return 1
615
616 async def test_fetchrow(pool):
617 i = random.randint(0, 20)
618 await asyncio.sleep(random.random() / 100)
619 r = await pool.fetchrow('SELECT {}::int'.format(i))
620 self.assertEqual(r, (i,))
621 return 1
622
623 async def test_fetchval(pool):
624 i = random.randint(0, 20)
625 await asyncio.sleep(random.random() / 100)
626 r = await pool.fetchval('SELECT {}::int'.format(i))
627 self.assertEqual(r, i)
628 return 1
629
630 async def test_execute(pool):
631 await asyncio.sleep(random.random() / 100)
632 r = await pool.execute('SELECT generate_series(0, 10)')
633 self.assertEqual(r, 'SELECT {}'.format(11))
634 return 1
635
636 async def test_execute_with_arg(pool):
637 i = random.randint(0, 20)
638 await asyncio.sleep(random.random() / 100)
639 r = await pool.execute('SELECT generate_series(0, $1)', i)
640 self.assertEqual(r, 'SELECT {}'.format(i + 1))
641 return 1
642
643 async def run(N, meth):
644 async with self.create_pool(database='postgres',
645 init_size=5,
646 min_size=0,
647 max_size=10) as pool:
648
649 coros = [meth(pool) for _ in range(N)]
650 res = await asyncio.gather(*coros)
651 self.assertEqual(res, [1] * N)
652
653 methods = [test_fetch, test_fetchrow, test_fetchval,
654 test_execute, test_execute_with_arg]
655
656 with tb.silence_asyncio_long_exec_warning():
657 for method in methods:
658 with self.subTest(method=method.__name__):
659 await run(200, method)
660
661 async def test_pool_connection_execute_many(self):
662 async def worker(pool):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected