Skip to content

Commit 6b0d686

Browse files
authored
chore(bigquery): fix timeout flakiness in job tests (#17826)
## The Problem Two unit tests in `google-cloud-bigquery` (`test_result_w_retry_wo_state` and `test_result_w_custom_retry`) were failing intermittently with a `TimeoutError` or `RetryError`. This flakiness occurs because the tests use a very short inner retry deadline of 0.1 seconds. Under heavy load (such as during parallel testing or on constrained continuous integration runners), this deadline can be exceeded, causing the test to fail confusingly. ## The Solution Increased the `deadline` parameter for the custom retry objects in both tests from 0.1 seconds to 1.0 seconds. This provides enough buffer for the test assertions to complete without timing out, aligning with other similar tests in the suite. ## Notes to Reviewers - This change only affects unit tests and does not alter production code. - This issue is blocking: - #17642 - #17608 Here is a snippet of the failure: ```python def test_result_w_retry_wo_state(global_time_lock): from google.cloud.bigquery.retry import DEFAULT_GET_JOB_TIMEOUT begun_job_resource = helpers._make_job_resource( job_id=JOB_ID, project_id=PROJECT, location="EU", started=True ) done_job_resource = helpers._make_job_resource( job_id=JOB_ID, project_id=PROJECT, location="EU", started=True, ended=True, ) conn = helpers.make_connection( exceptions.NotFound("not normally retriable"), begun_job_resource, exceptions.NotFound("not normally retriable"), done_job_resource, ) client = helpers._make_client(project=PROJECT, connection=conn) job = google.cloud.bigquery.job._AsyncJob( google.cloud.bigquery.job._JobReference(JOB_ID, PROJECT, "EU"), client ) custom_predicate = mock.Mock() custom_predicate.return_value = True custom_retry = google.api_core.retry.Retry( predicate=custom_predicate, initial=0.001, maximum=0.001, deadline=0.1, ) > assert job.result(retry=custom_retry) is job ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tests/unit/job/test_async_job_retry.py:115: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ google/cloud/bigquery/job/base.py:1047: in result return super(_AsyncJob, self).result(timeout=timeout, retry=retry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .nox/unit-3-12-test_type-unit/lib/python3.12/site-packages/google/api_core/future/polling.py:256: in result self._blocking_poll(timeout=timeout, retry=retry, polling=polling) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = _AsyncJob<project=test-project, location=EU, id=test-job-id> timeout = None retry = <google.api_core.retry.retry_unary.Retry object at 0x7ff2beda32c0> polling = <google.api_core.retry.retry_unary.Retry object at 0x7ff2beda01d0> def _blocking_poll(self, timeout=_DEFAULT_VALUE, retry=None, polling=None): """Poll and wait for the Future to be resolved.""" if self._result_set: return polling = polling or self._polling if timeout is not PollingFuture._DEFAULT_VALUE: polling = polling.with_timeout(timeout) try: polling(self._done_or_raise)(retry=retry) except exceptions.RetryError: > raise concurrent.futures.TimeoutError( f"Operation did not complete within the designated timeout of " f"{polling.timeout} seconds." ) E TimeoutError: Operation did not complete within the designated timeout of None seconds. ```
1 parent ef89c2c commit 6b0d686

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

packages/google-cloud-bigquery/tests/unit/job/test_async_job_retry.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
from unittest import mock
1616

1717
import google.api_core.retry
18+
import google.cloud.bigquery.job
1819
from google.api_core import exceptions
1920

2021
from . import helpers
21-
import google.cloud.bigquery.job
22-
2322

2423
PROJECT = "test-project"
2524
JOB_ID = "test-job-id"
@@ -110,7 +109,7 @@ def test_result_w_retry_wo_state(global_time_lock):
110109
predicate=custom_predicate,
111110
initial=0.001,
112111
maximum=0.001,
113-
deadline=0.1,
112+
deadline=1.0,
114113
)
115114
assert job.result(retry=custom_retry) is job
116115

packages/google-cloud-bigquery/tests/unit/job/test_query_job_retry.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import concurrent.futures
1415
from unittest import mock
1516

16-
import concurrent.futures
1717
import freezegun
18-
from google.api_core import exceptions
1918
import google.api_core.retry
2019
import pytest
21-
20+
from google.api_core import exceptions
2221
from google.cloud.bigquery.client import _MIN_GET_QUERY_RESULTS_TIMEOUT
2322
from google.cloud.bigquery.job import QueryJob
2423
from google.cloud.bigquery.retry import DEFAULT_GET_JOB_TIMEOUT
@@ -27,7 +26,6 @@
2726
from ..helpers import make_connection
2827
from .helpers import _make_client
2928

30-
3129
PROJECT = "test-project"
3230
JOB_ID = "test-job-id"
3331
QUERY = "select count(*) from persons"
@@ -105,7 +103,7 @@ def test_result_w_custom_retry(global_time_lock):
105103
initial=0.001,
106104
maximum=0.001,
107105
multiplier=1.0,
108-
deadline=0.1,
106+
deadline=1.0,
109107
predicate=custom_predicate,
110108
)
111109

0 commit comments

Comments
 (0)