| 792 | @pytest.mark.parametrize("autocommit", [True, False]) |
| 793 | @pytest.mark.crdb_skip("pg_terminate_backend") |
| 794 | async def test_getconn_check(dsn, caplog, autocommit): |
| 795 | caplog.set_level(logging.WARNING, logger="psycopg.pool") |
| 796 | |
| 797 | async with pool.AsyncConnectionPool( |
| 798 | dsn, |
| 799 | kwargs={"autocommit": autocommit}, |
| 800 | min_size=2, |
| 801 | check=pool.AsyncConnectionPool.check_connection, |
| 802 | ) as p: |
| 803 | await p.wait(1.0) |
| 804 | async with p.connection() as conn: |
| 805 | pid1 = conn.info.backend_pid |
| 806 | async with p.connection() as conn2: |
| 807 | pid2 = conn2.info.backend_pid |
| 808 | await conn.execute("select pg_terminate_backend(%s)", [pid2]) |
| 809 | |
| 810 | conn = await p.getconn() |
| 811 | try: |
| 812 | assert conn.info.transaction_status == TransactionStatus.IDLE |
| 813 | await conn.execute("select 1") |
| 814 | await conn.rollback() |
| 815 | conn2 = await p.getconn() |
| 816 | try: |
| 817 | assert conn2.info.transaction_status == TransactionStatus.IDLE |
| 818 | await conn2.execute("select 1") |
| 819 | await conn2.rollback() |
| 820 | pids = {c.info.backend_pid for c in [conn, conn2]} |
| 821 | finally: |
| 822 | await p.putconn(conn2) |
| 823 | finally: |
| 824 | await p.putconn(conn) |
| 825 | |
| 826 | assert pid1 in pids |
| 827 | assert pid2 not in pids |
| 828 | assert not caplog.records |
| 829 | |
| 830 | |
| 831 | @pytest.mark.slow |