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

Method test_pool_release_in_xact

tests/test_pool.py:577–606  ·  view source on GitHub ↗

Test that Connection.reset() closes any open transaction.

(self)

Source from the content-addressed store, hash-verified

575 self.assertEqual(len(cons), N)
576
577 async def test_pool_release_in_xact(self):
578 """Test that Connection.reset() closes any open transaction."""
579 async with self.create_pool(database='postgres',
580 init_size=1,
581 min_size=1,
582 max_size=1) as pool:
583 async def get_xact_id(con):
584 return await con.fetchval('select txid_current()')
585
586 with self.assertLoopErrorHandlerCalled('an active transaction'):
587 async with pool.acquire() as con:
588 real_con = con._con # unwrap PoolConnectionProxy
589
590 id1 = await get_xact_id(con)
591
592 tr = con.transaction()
593 self.assertIsNone(con._con._top_xact)
594 await tr.start()
595 self.assertIs(real_con._top_xact, tr)
596
597 id2 = await get_xact_id(con)
598 self.assertNotEqual(id1, id2)
599
600 self.assertIsNone(real_con._top_xact)
601
602 async with pool.acquire() as con:
603 self.assertIs(con._con, real_con)
604 self.assertIsNone(con._con._top_xact)
605 id3 = await get_xact_id(con)
606 self.assertNotEqual(id2, id3)
607
608 async def test_pool_connection_methods(self):
609 async def test_fetch(pool):

Callers

nothing calls this directly

Calls 5

transactionMethod · 0.80
create_poolMethod · 0.45
acquireMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected