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

Method test_pool_connection_methods

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

Source from the content-addressed store, hash-verified

545 self.assertNotEqual(id2, id3)
546
547 async def test_pool_connection_methods(self):
548 async def test_fetch(pool):
549 i = random.randint(0, 20)
550 await asyncio.sleep(random.random() / 100)
551 r = await pool.fetch('SELECT {}::int'.format(i))
552 self.assertEqual(r, [(i,)])
553 return 1
554
555 async def test_fetchrow(pool):
556 i = random.randint(0, 20)
557 await asyncio.sleep(random.random() / 100)
558 r = await pool.fetchrow('SELECT {}::int'.format(i))
559 self.assertEqual(r, (i,))
560 return 1
561
562 async def test_fetchval(pool):
563 i = random.randint(0, 20)
564 await asyncio.sleep(random.random() / 100)
565 r = await pool.fetchval('SELECT {}::int'.format(i))
566 self.assertEqual(r, i)
567 return 1
568
569 async def test_execute(pool):
570 await asyncio.sleep(random.random() / 100)
571 r = await pool.execute('SELECT generate_series(0, 10)')
572 self.assertEqual(r, 'SELECT {}'.format(11))
573 return 1
574
575 async def test_execute_with_arg(pool):
576 i = random.randint(0, 20)
577 await asyncio.sleep(random.random() / 100)
578 r = await pool.execute('SELECT generate_series(0, $1)', i)
579 self.assertEqual(r, 'SELECT {}'.format(i + 1))
580 return 1
581
582 async def run(N, meth):
583 async with self.create_pool(database='postgres',
584 min_size=5, max_size=10) as pool:
585
586 coros = [meth(pool) for _ in range(N)]
587 res = await asyncio.gather(*coros)
588 self.assertEqual(res, [1] * N)
589
590 methods = [test_fetch, test_fetchrow, test_fetchval,
591 test_execute, test_execute_with_arg]
592
593 with tb.silence_asyncio_long_exec_warning():
594 for method in methods:
595 with self.subTest(method=method.__name__):
596 await run(200, method)
597
598 async def test_pool_connection_execute_many(self):
599 async def worker(pool):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected