lidavidm commented on code in PR #3891:
URL: https://github.com/apache/arrow-adbc/pull/3891#discussion_r2723790740


##########
python/adbc_driver_postgresql/tests/test_dbapi.py:
##########
@@ -557,3 +557,33 @@ def test_connect_conn_kwargs_db_schema(postgres_uri: str, 
postgres: dbapi.Connec
     with dbapi.connect(postgres_uri, conn_kwargs={schema_key: schema_name}) as 
conn:
         option_value = conn.adbc_connection.get_option(schema_key)
         assert option_value == schema_name
+
+
+def test_server_terminates_connection(postgres_uri: str) -> None:
+    """Test that driver handles server terminating the connection gracefully.
+
+    Reproduces: https://github.com/apache/arrow-adbc/issues/3878
+    When the server terminates a connection, the driver should return an error
+    instead of crashing with a segfault.
+    """
+    with dbapi.connect(postgres_uri) as conn1:
+        with dbapi.connect(postgres_uri) as conn2:
+            # Get the backend PID of conn2
+            with conn2.cursor() as cur:
+                cur.execute("SELECT pg_backend_pid()")
+                backend_pid = cur.fetchone()[0]
+            conn2.commit()
+
+            # simulate a server side termination of a connection2
+            with conn1.cursor() as cur:
+                cur.execute(f"SELECT pg_terminate_backend({backend_pid})")
+            conn1.commit()
+
+            # Try to execute a query on the terminated connection
+            # This should raise an exception, NOT crash with a segfault
+            with pytest.raises(Exception) as exc_info:
+                with conn2.cursor() as cur:
+                    cur.execute("SELECT 1")
+
+            # Verify we got an error (not a crash)
+            assert exc_info.value is not None

Review Comment:
   This isn't necessary; `raises` will fail the test if there's no exception, 
and a crash will cause pytest to exit with a nonzero status already.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to