Skip to content

Commit

Permalink
Add a slight wait to allow for connection delay greater than 0.05
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Cox committed May 23, 2019
1 parent 933b608 commit 0225066
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions test/component/test_component.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import time
import uuid
from unittest import TestCase

Expand Down Expand Up @@ -64,13 +65,15 @@ def publish_to_pubsub(self, tx_id, case_id, questionnaire_id):
}
})

future = publisher.publish(topic_path,
data=data.encode('utf-8'),
eventType='OBJECT_FINALIZE',
bucketId='123',
objectId=tx_id)
if not future.done():
time.sleep(1)
try:
publisher.publish(topic_path,
data=data.encode('utf-8'),
eventType='OBJECT_FINALIZE',
bucketId='123',
objectId=tx_id) \
.result(timeout=30)
future.result(timeout=30)
except GoogleAPIError:
assert False, "Failed to publish message to pubsub"

Expand Down
15 changes: 9 additions & 6 deletions test/scripts/publish_message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import sys
import time
import uuid

from google.api_core.exceptions import GoogleAPIError
Expand All @@ -24,13 +25,15 @@
}
})

future = publisher.publish(topic_path,
data=data.encode('utf-8'),
eventType='OBJECT_FINALIZE',
bucketId='123',
objectId=tx_id)
if not future.done():
time.sleep(1)
try:
publisher.publish(topic_path,
data=data.encode('utf-8'),
eventType='OBJECT_FINALIZE',
bucketId='123',
objectId=tx_id) \
.result(timeout=30)
future.result(timeout=30)
except GoogleAPIError:
print("Failed to publish message to pubsub")

Expand Down

0 comments on commit 0225066

Please sign in to comment.