(self)
| 1519 | await pool.release(conn) |
| 1520 | |
| 1521 | async def test_pool_release_after_protocol_abort(self): |
| 1522 | pool = await self.create_pool(init_size=1, min_size=0, max_size=1) |
| 1523 | |
| 1524 | conn = await pool.acquire() |
| 1525 | raw_conn = conn._con |
| 1526 | holder = conn._holder |
| 1527 | terminated = asyncio.Event() |
| 1528 | conn.add_termination_listener(lambda _: terminated.set()) |
| 1529 | self.assertEqual(await conn.fetchval('SELECT 1'), 1) |
| 1530 | stmt = next(iter(raw_conn._stmt_cache.iter_statements())) |
| 1531 | |
| 1532 | raw_conn._protocol.abort() |
| 1533 | |
| 1534 | await pool.release(conn) |
| 1535 | |
| 1536 | # Releasing an aborted connection must finish connection cleanup. |
| 1537 | await asyncio.wait_for(terminated.wait(), timeout=1.0) |
| 1538 | self.assertTrue(stmt.closed) |
| 1539 | self.assertEqual(len(raw_conn._stmt_cache), 0) |
| 1540 | self.assertIsNone(holder._con) |
| 1541 | self.assertIsNone(holder._in_use) |
| 1542 | self.assertIsNone(conn._con) |
| 1543 | |
| 1544 | # Repeated release must not return the holder to the queue twice. |
| 1545 | await pool.release(conn) |
| 1546 | self.assertEqual(pool._queue.qsize(), 1) |
| 1547 | |
| 1548 | # The holder must reconnect and support queries after the abort. |
| 1549 | conn2 = await pool.acquire(timeout=1.0) |
| 1550 | self.assertIsNot(conn2._con, raw_conn) |
| 1551 | self.assertEqual(await conn2.fetchval('SELECT 1'), 1) |
| 1552 | await pool.release(conn2) |
| 1553 | await pool.close() |
| 1554 | |
| 1555 | |
| 1556 | @unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster') |
nothing calls this directly
no test coverage detected