Skip to content

Commit

Permalink
add retries around list_messages calls
Browse files Browse the repository at this point in the history
also use uuid for the resource name
  • Loading branch information
Takashi Matsuo committed Apr 2, 2020
1 parent 13f5070 commit c6254e4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
81 changes: 47 additions & 34 deletions healthcare/api-client/hl7v2/hl7v2_messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import random
import string
import sys
import time
import uuid

from gcp_devrel.testing import eventually_consistent

# Add datasets for bootstrapping datasets for testing
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'datasets')) # noqa
Expand All @@ -31,12 +33,8 @@

# assume we can access the OS provied raondom source.
random.seed()
dataset_id = 'test_dataset_{}_{}'.format(
int(time.time()),
''.join([random.choice(string.ascii_letters) for n in range(5)]))
hl7v2_store_id = 'test_hl7v2_store-{}-{}'.format(
int(time.time()),
''.join([random.choice(string.ascii_letters) for n in range(5)]))
dataset_id = 'test_dataset_{}'.format(uuid.uuid4())
hl7v2_store_id = 'test_hl7v2_store-{}'.format(uuid.uuid4())
hl7v2_message_file = 'resources/hl7-sample-ingest.json'
label_key = 'PROCESSED'
label_value = 'TRUE'
Expand Down Expand Up @@ -88,15 +86,20 @@ def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
hl7v2_store_id,
hl7v2_message_file)

hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

hl7v2_message_name = hl7v2_messages_list[0].get('name')
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]
hl7v2_message_id = ""
@eventually_consistent.call
def _():
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

assert len(hl7v2_messages_list) > 0
hl7v2_message_name = hl7v2_messages_list[0].get('name')
nonlocal hl7v2_message_id
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]

hl7v2_messages.get_hl7v2_message(
service_account_json,
Expand Down Expand Up @@ -131,15 +134,20 @@ def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
hl7v2_store_id,
hl7v2_message_file)

hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

hl7v2_message_name = hl7v2_messages_list[0].get('name')
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]
hl7v2_message_id = ""
@eventually_consistent.call
def _():
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

assert len(hl7v2_messages_list) > 0
hl7v2_message_name = hl7v2_messages_list[0].get('name')
nonlocal hl7v2_message_id
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]

hl7v2_messages.get_hl7v2_message(
service_account_json,
Expand Down Expand Up @@ -174,15 +182,20 @@ def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
hl7v2_store_id,
hl7v2_message_file)

hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

hl7v2_message_name = hl7v2_messages_list[0].get('name')
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]
hl7v2_message_id = ""
@eventually_consistent.call
def _():
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

assert len(hl7v2_messages_list) > 0
hl7v2_message_name = hl7v2_messages_list[0].get('name')
nonlocal hl7v2_message_id
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]

hl7v2_messages.patch_hl7v2_message(
service_account_json,
Expand Down
10 changes: 3 additions & 7 deletions healthcare/api-client/hl7v2/hl7v2_stores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import string
import sys
import time
import uuid

# Add datasets for bootstrapping datasets for testing
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'datasets')) # noqa
Expand All @@ -30,13 +31,8 @@

# assume we can access the OS provied raondom source.
random.seed()
dataset_id = 'test_dataset_{}_{}'.format(
int(time.time()),
''.join([random.choice(string.ascii_letters) for n in range(5)]))
hl7v2_store_id = 'test_hl7v2_store-{}-{}'.format(
int(time.time()),
''.join([random.choice(string.ascii_letters) for n in range(5)]))

dataset_id = 'test_dataset_{}'.format(uuid.uuid4())
hl7v2_store_id = 'test_hl7v2_store-{}'.format(uuid.uuid4())

@pytest.fixture(scope='module')
def test_dataset():
Expand Down
2 changes: 2 additions & 0 deletions healthcare/api-client/hl7v2/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pytest==5.3.2
gcp-devrel-py-tools==0.0.15
google-cloud-core

0 comments on commit c6254e4

Please sign in to comment.