Skip to content

fix(bigquery): implement robust wait loop for socket leak tests#17688

Draft
chalmerlowe wants to merge 1 commit into
mainfrom
fix/bigquery-socket-leak-robust
Draft

fix(bigquery): implement robust wait loop for socket leak tests#17688
chalmerlowe wants to merge 1 commit into
mainfrom
fix/bigquery-socket-leak-robust

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Intent

This PR addresses flakiness in the google-cloud-bigquery system tests that verify system resource cleanup (specifically open sockets).

The Problem

Some system tests in google-cloud-bigquery were performing instantaneous assertions on the number of open sockets immediately after client closure or garbage collection. These assertions are fragile because underlying transport layers (like gRPC) and OS socket reclamation can occur asynchronously in background threads. This leads to intermittent failures (flakiness) especially under varied environmental loads or parallel execution.

Solution

Refactored the fragile instantaneous checks in test_client.py and test_magics.py to use a Robust Wait-Loop pattern.

  • The tests now wait up to 3 seconds, checking periodically, to allow asynchronous cleanup to complete before asserting.
  • This pattern is already proven effective in other packages like google-cloud-pubsub.
  • Added explicit gc.collect() to test_magics.py to align with best practices for resource verification tests.

Note

Also includes some linting updates. Sorry.

@chalmerlowe chalmerlowe self-assigned this Jul 9, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant