From ae6592d5dc5721f590c9ed75387806807968ef8c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 8 Jan 2025 14:10:16 +0100 Subject: [PATCH] test: soften disconnection tests on platforms knwon to behave differently --- tests/test_connection.py | 14 +++++++++++++- tests/test_connection_async.py | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 64e5c9632..151f5fec0 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -884,8 +884,20 @@ def test_right_exception_on_server_disconnect(conn): @pytest.mark.slow +@pytest.mark.crdb("skip", reason="error result not returned") def test_right_exception_on_session_timeout(conn): + want_ex: type[psycopg.Error] = e.IdleInTransactionSessionTimeout + if sys.platform == "win32": + # No idea why this is needed and `test_right_exception_on_server_disconnect` + # works instead. Maybe the difference lies in the server we are testing + # with, not in the client. + want_ex = psycopg.OperationalError + conn.execute("SET SESSION idle_in_transaction_session_timeout = 100") sleep(0.2) - with pytest.raises(e.IdleInTransactionSessionTimeout): + with pytest.raises(want_ex) as ex: conn.execute("SELECT * from pg_tables") + + # This check is here to monitor if the behaviour on Window chamge. + # Rreceiving the same exception of other platform will be acceptable. + assert type(ex.value) is want_ex diff --git a/tests/test_connection_async.py b/tests/test_connection_async.py index a4635f790..c874ec55e 100644 --- a/tests/test_connection_async.py +++ b/tests/test_connection_async.py @@ -890,8 +890,20 @@ async def test_right_exception_on_server_disconnect(aconn): @pytest.mark.slow +@pytest.mark.crdb("skip", reason="error result not returned") async def test_right_exception_on_session_timeout(aconn): + want_ex: type[psycopg.Error] = e.IdleInTransactionSessionTimeout + if sys.platform == "win32": + # No idea why this is needed and `test_right_exception_on_server_disconnect` + # works instead. Maybe the difference lies in the server we are testing + # with, not in the client. + want_ex = psycopg.OperationalError + await aconn.execute("SET SESSION idle_in_transaction_session_timeout = 100") await asleep(0.2) - with pytest.raises(e.IdleInTransactionSessionTimeout): + with pytest.raises(want_ex) as ex: await aconn.execute("SELECT * from pg_tables") + + # This check is here to monitor if the behaviour on Window chamge. + # Rreceiving the same exception of other platform will be acceptable. + assert type(ex.value) is want_ex -- 2.39.5