Skip to content

Commit e12e3c5

Browse files
committed
feat(bigquery): add debug info to socket leak test
1 parent b7fa7df commit e12e3c5

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

packages/google-cloud-bigquery/tests/system/test_client.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,26 @@ def test_dbapi_connection_does_not_leak_sockets(self):
22132213
break
22142214
time.sleep(0.1)
22152215

2216-
self.assertLessEqual(conn_count_end, conn_count_start)
2216+
try:
2217+
self.assertLessEqual(conn_count_end, conn_count_start)
2218+
except AssertionError as e:
2219+
# Due to flakiness in this test (likely caused by OS cleanup delays or
2220+
# non-deterministic garbage collection of sockets), we want to capture
2221+
# the detailed state of connections in future failing runs to help
2222+
# decrease false positives and identify the root cause.
2223+
conn_debug = [
2224+
f"Status: {c.status}, Laddr: {c.laddr}, Raddr: {c.raddr}"
2225+
for c in current_process.net_connections()
2226+
]
2227+
debug_msg = "\n".join(conn_debug)
2228+
2229+
raise AssertionError(
2230+
f"{e}\n\n"
2231+
f"--- Socket Leak Debug Info ---\n"
2232+
f"Start Count: {conn_count_start}\n"
2233+
f"End Count: {conn_count_end}\n"
2234+
f"Current Connections:\n{debug_msg}"
2235+
)
22172236

22182237
def _load_table_for_dml(self, rows, dataset_id, table_id):
22192238
from google.cloud._testing import _NamedTemporaryFile

0 commit comments

Comments
 (0)