75
75
76
76
preset = "preset/web-hd"
77
77
job_succeeded_state = "ProcessingState.SUCCEEDED"
78
+ job_running_state = "ProcessingState.RUNNING"
78
79
79
80
80
81
@pytest .fixture (scope = "module" )
@@ -105,7 +106,7 @@ def test_create_job_from_preset(capsys, test_bucket):
105
106
106
107
time .sleep (30 )
107
108
108
- _assert_job_state_succeeded (capsys , job_id )
109
+ _assert_job_state_succeeded_or_running (capsys , job_id )
109
110
110
111
list_jobs .list_jobs (project_id , location )
111
112
out , _ = capsys .readouterr ()
@@ -144,7 +145,7 @@ def test_create_job_from_template(capsys, test_bucket):
144
145
145
146
time .sleep (30 )
146
147
147
- _assert_job_state_succeeded (capsys , job_id )
148
+ _assert_job_state_succeeded_or_running (capsys , job_id )
148
149
149
150
list_jobs .list_jobs (project_id , location )
150
151
out , _ = capsys .readouterr ()
@@ -178,7 +179,7 @@ def test_create_job_from_ad_hoc(capsys, test_bucket):
178
179
179
180
time .sleep (30 )
180
181
181
- _assert_job_state_succeeded (capsys , job_id )
182
+ _assert_job_state_succeeded_or_running (capsys , job_id )
182
183
183
184
list_jobs .list_jobs (project_id , location )
184
185
out , _ = capsys .readouterr ()
@@ -399,7 +400,8 @@ def test_create_job_with_concatenated_inputs(capsys, test_bucket):
399
400
assert "Deleted job" in out
400
401
401
402
402
- # Retrying up to 10 mins.
403
+ # Retrying up to 10 mins. This function checks if the job completed
404
+ # successfully.
403
405
@backoff .on_exception (backoff .expo , AssertionError , max_time = 600 )
404
406
def _assert_job_state_succeeded (capsys , job_id ):
405
407
try :
@@ -411,6 +413,20 @@ def _assert_job_state_succeeded(capsys, job_id):
411
413
assert job_succeeded_state in out
412
414
413
415
416
+ # Retrying up to 10 mins. This function checks if the job is running or has
417
+ # completed. Both of these conditions signal the API is functioning. The test
418
+ # can list or delete a job that is running or completed with no ill effects.
419
+ @backoff .on_exception (backoff .expo , AssertionError , max_time = 600 )
420
+ def _assert_job_state_succeeded_or_running (capsys , job_id ):
421
+ try :
422
+ get_job_state .get_job_state (project_id , location , job_id )
423
+ except HttpError as err :
424
+ raise AssertionError (f"Could not get job state: { err .resp .status } " )
425
+
426
+ out , _ = capsys .readouterr ()
427
+ assert (job_succeeded_state in out ) or (job_running_state in out )
428
+
429
+
414
430
def _assert_file_in_bucket (capsys , test_bucket , directory_and_filename ):
415
431
blob = test_bucket .blob (directory_and_filename )
416
432
assert blob .exists ()
0 commit comments