From c8e895281151a95da607541515e07e164f5fac7b Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 31 Aug 2021 16:42:07 +0200 Subject: [PATCH] Fix tests retry if the failure leaves the connection in bad state --- tests/test_server_cursor.py | 3 +++ tests/test_server_cursor_async.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/tests/test_server_cursor.py b/tests/test_server_cursor.py index 67773c270..132fa1a93 100644 --- a/tests/test_server_cursor.py +++ b/tests/test_server_cursor.py @@ -96,6 +96,9 @@ def test_binary_cursor_text_override(conn): def test_close(conn, recwarn, retries): for retry in retries: with retry: + if conn.info.transaction_status == conn.TransactionStatus.INTRANS: + # connection dirty from previous failure + conn.execute("close foo") recwarn.clear() cur = conn.cursor("foo") cur.execute("select generate_series(1, 10) as bar") diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py index 5814ed7f4..d240ac39d 100644 --- a/tests/test_server_cursor_async.py +++ b/tests/test_server_cursor_async.py @@ -98,6 +98,12 @@ async def test_binary_cursor_text_override(aconn): async def test_close(aconn, recwarn, retries): async for retry in retries: with retry: + if ( + aconn.info.transaction_status + == aconn.TransactionStatus.INTRANS + ): + # connection dirty from previous failure + await aconn.execute("close foo") recwarn.clear() cur = aconn.cursor("foo") await cur.execute("select generate_series(1, 10) as bar") -- 2.47.3