Still some weirdness here around: the method raises an exception on my
box (both with unix and tcp socket) but it seems to raise still a valid
number on certain databases on Travis. Make sure, in the test, at least
that it is a reasonable value.
@property
def socket(self) -> int:
- return self._call_int(impl.PQsocket)
+ rv = self._call_int(impl.PQsocket)
+ if rv == -1:
+ raise e.OperationalError("the connection is lost")
+ return rv
@property
def backend_pid(self) -> int:
@property
def socket(self) -> int:
- return _call_int(self, libpq.PQsocket)
+ rv = _call_int(self, libpq.PQsocket)
+ if rv == -1:
+ raise PQerror("the connection is lost")
+ return rv
@property
def backend_pid(self) -> int:
return rv
-cdef int _call_int(PGconn pgconn, conn_int_f func) except -1:
+cdef int _call_int(PGconn pgconn, conn_int_f func) except -2:
"""
Call one of the pgconn libpq functions returning an int.
"""
if not _ensure_pgconn(pgconn):
- return -1
+ return -2
return func(pgconn.pgconn_ptr)
pgconn.server_version
+def test_socket(pgconn):
+ socket = pgconn.socket
+ assert socket > 0
+ pgconn.exec_(
+ f"select pg_terminate_backend({pgconn.backend_pid})".encode("utf8")
+ )
+ # TODO: on my box it raises OperationalError as it should. Not on Travis,
+ # so let's see if at least an ok value comes out of it.
+ try:
+ assert pgconn.socket == socket
+ except psycopg3.OperationalError:
+ pass
+
+
def test_error_message(pgconn):
assert pgconn.error_message == b""
res = pgconn.exec_(b"wat")