Skip to content

Commit e8c064b

Browse files
authored
Merge pull request googleapis#2214 from tseaver/2111-pubsub-topic-exists-unavailable
Add retry for flaky 'topic.exists()' check.
2 parents 3784293 + 13a35cd commit e8c064b

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

system_tests/pubsub.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import os
1616
import unittest
1717

18+
from google.gax.errors import GaxError
19+
from grpc import StatusCode
20+
from grpc._channel import _Rendezvous
1821
import httplib2
1922

2023
from gcloud import _helpers
@@ -24,10 +27,18 @@
2427

2528
from retry import RetryInstanceState
2629
from retry import RetryResult
30+
from retry import RetryErrors
2731
from system_test_utils import EmulatorCreds
2832
from system_test_utils import unique_resource_id
2933

3034

35+
def _unavailable(exc):
36+
return _helpers.exc_to_code(exc) == StatusCode.UNAVAILABLE
37+
38+
39+
retry_unavailable = RetryErrors((GaxError, _Rendezvous), _unavailable)
40+
41+
3142
class Config(object):
3243
"""Run-time configuration to be modified at set-up.
3344
@@ -124,7 +135,7 @@ def test_create_subscription_w_ack_deadline(self):
124135
def test_list_subscriptions(self):
125136
TOPIC_NAME = 'list-sub' + unique_resource_id('-')
126137
topic = Config.CLIENT.topic(TOPIC_NAME)
127-
self.assertFalse(topic.exists())
138+
self.assertFalse(retry_unavailable(topic.exists)())
128139
topic.create()
129140
self.to_delete.append(topic)
130141
empty, _ = topic.list_subscriptions()

0 commit comments

Comments
 (0)