Skip to content

Commit 20691ac

Browse files
committed
migrate job_helpers test
1 parent f933480 commit 20691ac

File tree

2 files changed

+61
-42
lines changed

2 files changed

+61
-42
lines changed

tests/unit/test__job_helpers.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -512,48 +512,6 @@ def test_query_and_wait_retries_job(global_time_lock):
512512
assert kwargs["path"] == request_path
513513

514514

515-
def test_query_and_wait_retries_job_times_out(global_time_lock):
516-
freezegun.freeze_time(auto_tick_seconds=100)
517-
client = mock.create_autospec(Client)
518-
client._call_api.__name__ = "_call_api"
519-
client._call_api.__qualname__ = "Client._call_api"
520-
client._call_api.__annotations__ = {}
521-
client._call_api.__type_params__ = ()
522-
client._call_api.side_effect = (
523-
google.api_core.exceptions.BadGateway("retry me"),
524-
google.api_core.exceptions.InternalServerError("job_retry me"),
525-
google.api_core.exceptions.BadGateway("retry me"),
526-
google.api_core.exceptions.InternalServerError("job_retry me"),
527-
)
528-
529-
with pytest.raises(google.api_core.exceptions.RetryError) as exc_info:
530-
_job_helpers.query_and_wait(
531-
client,
532-
query="SELECT 1",
533-
location="request-location",
534-
project="request-project",
535-
job_config=None,
536-
page_size=None,
537-
max_results=None,
538-
retry=retries.Retry(
539-
lambda exc: isinstance(exc, google.api_core.exceptions.BadGateway),
540-
multiplier=1.0,
541-
).with_deadline(
542-
200.0
543-
), # Since auto_tick_seconds is 100, we should get at least 1 retry.
544-
job_retry=retries.Retry(
545-
lambda exc: isinstance(
546-
exc, google.api_core.exceptions.InternalServerError
547-
),
548-
multiplier=1.0,
549-
).with_deadline(400.0),
550-
)
551-
552-
assert isinstance(
553-
exc_info.value.cause, google.api_core.exceptions.InternalServerError
554-
)
555-
556-
557515
def test_query_and_wait_sets_job_creation_mode():
558516
client = mock.create_autospec(Client)
559517
client.default_job_creation_mode = "JOB_CREATION_OPTIONAL"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)