8000 fix: assert true if a test job is running but is stuck (#7387) · aviper/python-docs-samples@6e0f38d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e0f38d

Browse files
authored
fix: assert true if a test job is running but is stuck (GoogleCloudPlatform#7387)
* fix for flaky tests * add comment about listing or deleting a running job
1 parent 8540237 commit 6e0f38d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

media/transcoder/job_test.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
preset = "preset/web-hd"
7777
job_succeeded_state = "ProcessingState.SUCCEEDED"
78+
job_running_state = "ProcessingState.RUNNING"
7879

7980

8081
@pytest.fixture(scope="module")
@@ -105,7 +106,7 @@ def test_create_job_from_preset(capsys, test_bucket):
105106

106107
time.sleep(30)
107108

108-
_assert_job_state_succeeded(capsys, job_id)
109+
_assert_job_state_succeeded_or_running(capsys, job_id)
109110

110111
list_jobs.list_jobs(project_id, location)
111112
out, _ = capsys.readouterr()
@@ -144,7 +145,7 @@ def test_create_job_from_template(capsys, test_bucket):
144145

145146
time.sleep(30)
146147

147-
_assert_job_state_succeeded(capsys, job_id)
148+
_assert_job_state_succeeded_or_running(capsys, job_id)
148149

149150
list_jobs.list_jobs(project_id, location)
150151
out, _ = capsys.readouterr()
@@ -178,7 +179,7 @@ def test_create_job_from_ad_hoc(capsys, test_bucket):
178179

179180
time.sleep(30)
180181

181-
_assert_job_state_succeeded(capsys, job_id)
182+
_assert_job_state_succeeded_or_running(capsys, job_id)
182183

183184
list_jobs.list_jobs(project_id, location)
184185
out, _ = capsys.readouterr()
@@ -399,7 +400,8 @@ def test_create_job_with_concatenated_inputs(capsys, test_bucket):
399400
assert "Deleted job" in out
400401

401402

402-
# Retrying up to 10 mins.
403+
# Retrying up to 10 mins. This function checks if the job completed
404+
# successfully.
403405
@backoff.on_exception(backoff.expo, AssertionError, max_time=600)
404406
def _assert_job_state_succeeded(capsys, job_id):
405407
try:
@@ -411,6 +413,20 @@ def _assert_job_state_succeeded(capsys, job_id):
411413
assert job_succeeded_state in out
412414

413415

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+
414430
def _assert_file_in_bucket(capsys, test_bucket, directory_and_filename):
415431
blob = test_bucket.blob(directory_and_filename)
416432
assert blob.exists()

0 commit comments

Comments
 (0)
0