]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: soften disconnection tests on platforms knwon to behave differently 989/head
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 8 Jan 2025 13:10:16 +0000 (14:10 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 9 Jan 2025 13:04:54 +0000 (14:04 +0100)
tests/test_connection.py
tests/test_connection_async.py

index 64e5c963222b3f6f36a3bef59da68e39ccb97cf0..151f5fec0840602357ee9ccf96f5273c367ce8a5 100644 (file)
@@ -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
index a4635f790906dc11726eae796e1816c8810910e1..c874ec55e32a967f044e400c596d6f9c003277c5 100644 (file)
@@ -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