3333import pytest
3434import requests
3535
36+ import google .api
37+
3638
3739try :
3840 import opentelemetry
@@ -5355,7 +5357,7 @@ def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_retries_404(self):
53555357 conn = client ._connection = make_connection (
53565358 # We're mocking QueryJob._begin, so this is only going to be
53575359 # jobs.get requests and responses.
5358- ValueError ( "not normally retriable, but you said it was " ),
5360+ google . api_core . exceptions . TooManyRequests ( "this is retriable by default " ),
53595361 google .api_core .exceptions .NotFound ("we lost your job" ),
53605362 google .api_core .exceptions .NotFound ("we lost your job again, sorry" ),
53615363 {
@@ -5367,11 +5369,6 @@ def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_retries_404(self):
53675369 },
53685370 )
53695371
5370- retry = google .cloud .bigquery .retry .DEFAULT_RETRY .with_predicate (
5371- # We should respect the predicate the user provides,
5372- # but amend it with allowing 404 in this particular situation.
5373- lambda exc : isinstance (exc , ValueError )
5374- )
53755372 job_create_error = google .api_core .exceptions .Conflict ("Job already exists." )
53765373 job_begin_patcher = mock .patch .object (
53775374 bqjob .QueryJob , "_begin" , side_effect = job_create_error
@@ -5386,7 +5383,7 @@ def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_retries_404(self):
53865383 # If get job request fails there does exist a job
53875384 # with this ID already, retry 404 until we get it (or fails for a
53885385 # non-retriable reason, see other tests).
5389- result = client .query ("SELECT 1;" , job_id = None , retry = retry )
5386+ result = client .query ("SELECT 1;" , job_id = None )
53905387
53915388 jobs_get_path = mock .call (
53925389 method = "GET" ,
@@ -5404,7 +5401,7 @@ def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_retries_404(self):
54045401 )
54055402 assert result .job_id == job_id
54065403
5407- def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_retries_404_query_job (
5404+ def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_retries_404_and_query_job_insert (
54085405 self ,
54095406 ):
54105407 """Regression test for https://github.com/googleapis/python-bigquery/issues/2134
@@ -5441,16 +5438,21 @@ def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_retries_404_query_job
54415438 "make_job_id" ,
54425439 side_effect = [job_id_1 , job_id_2 ],
54435440 )
5441+ retry_patcher = mock .patch .object (
5442+ google .cloud .bigquery .retry ,
5443+ "_DEFAULT_GET_JOB_CONFLICT_RETRY" ,
5444+ retry ,
5445+ )
54445446
54455447 with freezegun .freeze_time (
54465448 "2025-01-01 00:00:00" ,
54475449 # 10x the retry deadline to guarantee a timeout.
5448- auto_tick_seconds = 10 ,
5449- ), job_begin_patcher , job_id_patcher :
5450+ auto_tick_seconds = 100 ,
5451+ ), job_begin_patcher , job_id_patcher , retry_patcher :
54505452 # If get job request fails there does exist a job
54515453 # with this ID already, retry 404 until we get it (or fails for a
54525454 # non-retriable reason, see other tests).
5453- result = client .query ("SELECT 1;" , job_id = None , retry = retry )
5455+ result = client .query ("SELECT 1;" , job_id = None )
54545456
54555457 jobs_get_path_1 = mock .call (
54565458 method = "GET" ,
0 commit comments