10000 test: fix flaky healthcare samples (#7440) · mortn/python-docs-samples@6cf3154 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6cf3154

Browse files
authored
test: fix flaky healthcare samples (GoogleCloudPlatform#7440)
1 parent 57ce0e5 commit 6cf3154

File tree

4 files changed

+65
-40
lines changed

4 files changed

+65
-40
lines changed

healthcare/api-client/v1/fhir/fhir_resources_test.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
resource_type = "Patient"
3939

4040

41-
BACKOFF_MAX_TIME = 500
41+
BACKOFF_MAX_TIME = 750
4242

4343

4444
@pytest.fixture(scope="module")
@@ -161,14 +161,20 @@ def clean_up():
161161

162162

163163
def test_create_patient(test_dataset, test_fhir_store, capsys):
164-
# Manually create a new Patient here to test that creating a Patient
165-
# works.
166-
fhir_resources.create_patient(
167-
project_id,
168-
location,
169-
dataset_id,
170-
fhir_store_id,
171-
)
164+
# We see HttpErrors with "dataset not initialized" message.
165+
# I think retry will mitigate the flake.
166+
# Googlers see b/189121491 .
167+
@backoff.on_exception(backoff.expo, HttpError, max_time=BACKOFF_MAX_TIME)
168+
def create():
169+
# Manually create a new Patient here to test that creating a Patient
170+
# works.
171+
fhir_resources.create_patient(
172+
project_id,
173+
location,
174+
dataset_id,
175+
fhir_store_id,
176+
)
177+
create()
172178

173179
out, _ = capsys.readouterr()
174180

@@ -269,14 +275,20 @@ def test_execute_bundle(test_dataset, test_fhir_store, capsys):
269275

270276

271277
def test_delete_patient(test_dataset, test_fhir_store, test_patient, capsys):
272-
fhir_resources.delete_resource(
273-
project_id,
274-
location,
275-
dataset_id,
276-
fhir_store_id,
277-
resource_type,
278-
test_patient,
279-
)
278+
# We see HttpErrors with "dataset not initialized" message.
279+
# I think retry will mitigate the flake.
280+
# Googlers see b/189121491 .
281+
@backoff.on_exception(backoff.expo, HttpError, max_time=BACKOFF_MAX_TIME)
282+
def delete():
283+
fhir_resources.delete_resource(
284+
project_id,
285+
location,
286+
dataset_id,
287+
fhir_store_id,
288+
resource_type,
289+
test_patient,
290+
)
291+
delete()
280292

281293
out, _ = capsys.readouterr()
282294

healthcare/api-client/v1/fhir/fhir_stores_test.py

Lines changed: 1 addition & 1 deletion

healthcare/api-client/v1beta1/fhir/fhir_resources_test.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import_object = "{}/{}".format(gcs_uri, source_file_name)
4242

4343

44-
BACKOFF_MAX_TIME = 500
44+
BACKOFF_MAX_TIME = 750
4545

4646

4747
@pytest.fixture(scope="module")
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
resource_type = "Patient"
3434

3535

36-
BACKOFF_MAX_TIME = 500
36+
BACKOFF_MAX_TIME = 750
3737

3838

3939
# A giveup callback for backoff.
@@ -103,16 +103,22 @@ def test_patient():
103103

104104

105105
def test_create_patient(test_dataset, test_fhir_store, capsys):
106-
# Manually create a new Patient here to test that creating a Patient
107-
# works.
108-
fhir_resources.create_patient(
109-
service_account_json,
110-
base_url,
111-
project_id,
112-
cloud_region,
113-
dataset_id,
114-
fhir_store_id,
115-
)
106+
# We see HttpErrors with "dataset not initialized" message.
107+
# I think retry will mitigate the flake.
108+
# Googlers see b/189121491 .
109+
@backoff.on_exception(backoff.expo, HTTPError, max_time=BACKOFF_MAX_TIME)
110+
def create():
111+
# Manually create a new Patient here to test that creating a Patient
112+
# works.
113+
fhir_resources.create_patient(
114+
service_account_json,
115+
base_url,
116+
project_id,
117+
cloud_region,
118+
dataset_id,
119+
fhir_store_id,
120+
)
121+
create()
116122

117123
out, _ = capsys.readouterr()
118124

@@ -312,16 +318,22 @@ def conditional_delete_resource():
312318

313319

314320
def test_delete_patient(test_dataset, test_fhir_store, test_patient, capsys):
315-
fhir_resources.delete_resource(
316-
service_account_json,
317-
base_url,
318-
project_id,
319-
cloud_region,
320-
dataset_id,
321-
fhir_store_id,
322-
resource_type,
323-
test_patient,
324-
)
321+
# We see HttpErrors with "dataset not initialized" message.
322+
# I think retry will mitigate the flake.
323+
# Googlers see b/189121491 .
324+
@backoff.on_exception(backoff.expo, HTTPError, max_time=BACKOFF_MAX_TIME)
325+
def delete():
326+
fhir_resources.delete_resource(
327+
service_account_json,
328+
base_url,
329+
project_id,
330+
cloud_region,
331+
dataset_id,
332+
fhir_store_id,
333+
resource_type,
334+
test_patient,
335+
)
336+
delete()
325337

326338
out, _ = capsys.readouterr()
327339

healthcare/api-client/v1beta1/fhir/fhir_stores_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
test_fhir_store_id = "test_fhir_store-{}".format(uuid.uuid4())
3232

3333

34-
BACKOFF_MAX_TIME = 500
34+
BACKOFF_MAX_TIME = 750
3535

3636

3737
@pytest.fixture(scope="module")
@@ -64,6 +64,7 @@ def test_fhir_store():
6464
def test_create_delete_fhir_store(test_dataset, capsys):
6565
# We see HttpErrors with "dataset not initialized" message.
6666
# I think retry will mitigate the flake.
67+
# Googlers see b/189121491 .
6768
@backoff.on_exception(backoff.expo, HTTPError, max_time=BACKOFF_MAX_TIME)
6869
def create():
6970
fhir_stores.create_fhir_store(

0 commit comments

Comments
 (0)
0