8000 fix(healthcare): add more retries for mitigating flakes (#5237) · bpeters/python-docs-samples@9c8afca · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c8afca

Browse files
author
Takashi Matsuo
authored
fix(healthcare): add more retries for mitigating flakes (GoogleCloudPlatform#5237)
* fix(healthcare): add more retries for mitigating flakes fixes GoogleCloudPlatform#5211 fixes GoogleCloudPlatform#5210 fixes GoogleCloudPlatform#5209 fixes GoogleCloudPlatform#5205 * fix(healthcare): longer retry timeout, one more retry
1 parent 5c8b10f commit 9c8afca

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

healthcare/api-client/v1/datasets/datasets_test.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@ def test_CRUD_dataset(capsys, crud_dataset_id):
137137
cloud_region,
138138
crud_dataset_id)
139139

140-
datasets.get_dataset(
141-
project_id, cloud_region, crud_dataset_id)
140+
@retry(
141+
wait_exponential_multiplier=1000,
142+
wait_exponential_max=10000,
143+
stop_max_attempt_number=10,
144+
retry_on_exception=retry_if_server_exception)
145+
def get_dataset():
146+
datasets.get_dataset(
147+
project_id, cloud_region, crud_dataset_id)
148+
149+
get_dataset()
142150

143151
datasets.list_datasets(
144152
project_id, cloud_region)
@@ -156,11 +164,19 @@ def test_CRUD_dataset(capsys, crud_dataset_id):
156164

157165

158166
def test_patch_dataset(capsys, test_dataset):
159-
datasets.patch_dataset(
160-
project_id,
161-
cloud_region,
162-
dataset_id,
163-
time_zone)
167+
# To mitigate the flake with HttpErrors.
168+
@retry(
169+
wait_exponential_multiplier=1000,
170+
wait_exponential_max=10000,
171+
stop_max_attempt_number=10,
172+
retry_on_exception=retry_if_server_exception)
173+
def run_sample():
174+
datasets.patch_dataset(
175+
project_id,
176+
cloud_region,
177+
dataset_id,
178+
time_zone)
179+
run_sample()
164180

165181
out, _ = capsys.readouterr()
166182

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ def test_dataset():
5454

5555
@pytest.fixture(scope="module")
5656
def test_fhir_store():
57-
fhir_store = fhir_stores.create_fhir_store(
58-
service_account_json, project_id, cloud_region, dataset_id, fhir_store_id
59-
)
57+
# We see HttpErrors with "dataset not initialized" message.
58+
# I think retry will mitigate the flake.
59+
@backoff.on_exception(backoff.expo, HTTPError, max_time=120)
60+
def create_fhir_store():
61+
return fhir_stores.create_fhir_store(
62+
service_account_json, project_id, cloud_region, dataset_id, fhir_store_id
63+
)
64+
fhir_store = create_fhir_store()
6065

6166
yield fhir_store
6267

0 commit comments

Comments
 (0)
0