|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import freezegun |
| 16 | +import google.api_core.exceptions |
| 17 | +from google.api_core import retry as retries |
| 18 | +import pytest |
| 19 | + |
| 20 | +from google.cloud.bigquery import _job_helpers |
| 21 | + |
| 22 | +from . import helpers |
| 23 | + |
| 24 | + |
| 25 | +def test_query_and_wait_retries_job_times_out(global_time_lock): |
| 26 | + with freezegun.freeze_time(auto_tick_seconds=100): |
| 27 | + conn = helpers.make_connection( |
| 28 | + google.api_core.exceptions.BadGateway("retry me"), |
| 29 | + google.api_core.exceptions.InternalServerError("job_retry me"), |
| 30 | + google.api_core.exceptions.BadGateway("retry me"), |
| 31 | + google.api_core.exceptions.InternalServerError("job_retry me"), |
| 32 | + ) |
| 33 | + client = helpers.make_client(project="client-project") |
| 34 | + client._connection = conn |
| 35 | + |
| 36 | + with pytest.raises(google.api_core.exceptions.RetryError) as exc_info: |
| 37 | + _job_helpers.query_and_wait( |
| 38 | + client, |
| 39 | + query="SELECT 1", |
| 40 | + location="request-location", |
| 41 | + project="request-project", |
| 42 | + job_config=None, |
| 43 | + page_size=None, |
| 44 | + max_results=None, |
| 45 | + retry=retries.Retry( |
| 46 | + lambda exc: isinstance(exc, google.api_core.exceptions.BadGateway), |
| 47 | + multiplier=1.0, |
| 48 | + ).with_deadline( |
| 49 | + 200.0 |
| 50 | + ), # Since auto_tick_seconds is 100, we should get at least 1 retry. |
| 51 | + job_retry=retries.Retry( |
| 52 | + lambda exc: isinstance( |
| 53 | + exc, google.api_core.exceptions.InternalServerError |
| 54 | + ), |
| 55 | + multiplier=1.0, |
| 56 | + ).with_deadline(400.0), |
| 57 | + ) |
| 58 | + |
| 59 | + assert isinstance( |
| 60 | + exc_info.value.cause, google.api_core.exceptions.InternalServerError |
| 61 | + ) |
0 commit comments