Skip to content

Commit 7e54629

Browse files
tests(session): improve session table deletion polling and add flaky retries (#18097)
In `tests/system/small/test_bq_sessions.py`: 1. `test_bq_session_create_temp_table_clustered` tests that session temporary tables are deleted after closing the session. Because BigQuery cleans up `_SESSION` dataset resources asynchronously, during high CI load this can take longer than 60 seconds, causing `pytest.raises(NotFound)` to fail prematurely. 2. `test_bq_session_create_multi_temp_tables` creates 10 concurrent tables across threads and can encounter transient DDL rate limiting or network latency under parallel test execution (`pytest-xdist`). ### Changes - Updated `test_bq_session_create_temp_table_clustered` to poll for table deletion for up to 120s with 5s intervals and assert `table_deleted`. - Added `@pytest.mark.flaky(retries=2, delay=10)` to both session tests to prevent transient CI test flakes. Fixes #<545778300> 🦕 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent bc1d6dd commit 7e54629

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

packages/bigframes/tests/system/small/test_bq_sessions.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def session_resource_manager(
4444
)
4545

4646

47+
@pytest.mark.flaky(reruns=2, reruns_delay=10)
4748
def test_bq_session_create_temp_table_clustered(bigquery_client: bigquery.Client):
4849
session_resource_manager = bigquery_session.SessionResourceManager(
4950
bigquery_client, "US", publisher=bigframes.core.events.Publisher()
@@ -60,14 +61,21 @@ def test_bq_session_create_temp_table_clustered(bigquery_client: bigquery.Client
6061
assert result_table.clustering_fields == cluster_cols
6162

6263
session_resource_manager.close()
63-
with pytest.raises(google.api_core.exceptions.NotFound):
64-
# It may take time for the underlying tables to get cleaned up after
65-
# closing the session, so wait at least 1 minute to check.
66-
for _ in range(6):
64+
# BigQuery cleans up temporary session tables asynchronously after closing the session.
65+
table_deleted = False
66+
for _ in range(24):
67+
try:
6768
bigquery_client.get_table(session_table_ref)
68-
time.sleep(10)
69+
time.sleep(5)
70+
except google.api_core.exceptions.NotFound:
71+
table_deleted = True
72+
break
73+
assert table_deleted, (
74+
f"Session table {session_table_ref} was not deleted after closing session."
75+
)
6976

7077

78+
@pytest.mark.flaky(reruns=2, reruns_delay=10)
7179
def test_bq_session_create_multi_temp_tables(bigquery_client: bigquery.Client):
7280
session_resource_manager = bigquery_session.SessionResourceManager(
7381
bigquery_client, "US", publisher=bigframes.core.events.Publisher()

0 commit comments

Comments
 (0)