@@ -243,6 +243,7 @@ def test_subscription_iam_policy(self):
243243 self .assertEqual (new_policy .viewers , policy .viewers )
244244
245245 def test_fetch_delete_subscription_w_deleted_topic (self ):
246+ from gcloud .iterator import MethodIterator
246247 TO_DELETE = 'delete-me' + unique_resource_id ('-' )
247248 ORPHANED = 'orphaned' + unique_resource_id ('-' )
248249 topic = Config .CLIENT .topic (TO_DELETE )
@@ -251,13 +252,15 @@ def test_fetch_delete_subscription_w_deleted_topic(self):
251252 subscription .create ()
252253 topic .delete ()
253254
254- all_subs = []
255- token = None
256- while True :
257- subs , token = Config .CLIENT .list_subscriptions (page_token = token )
258- all_subs .extend (subs )
259- if token is None :
260- break
255+ def _fetch ():
256+ return list (MethodIterator (Config .CLIENT .list_subscriptions ))
257+
258+ def _found_orphan (result ):
259+ return any (subscription for subscription in result
260+ if subscription .name == ORPHANED )
261+
262+ retry_until_found_orphan = RetryResult (_found_orphan )
263+ all_subs = retry_until_found_orphan (_fetch )()
261264
262265 created = [subscription for subscription in all_subs
263266 if subscription .name == ORPHANED ]
@@ -268,8 +271,8 @@ def _no_topic(instance):
268271 return instance .topic is None
269272
270273 # Wait for the topic to clear: up to 63 seconds (2 ** 8 - 1)
271- retry = RetryInstanceState (_no_topic , max_tries = 7 )
272- retry (orphaned .reload )()
274+ retry_until_no_topic = RetryInstanceState (_no_topic , max_tries = 7 )
275+ retry_until_no_topic (orphaned .reload )()
273276
274277 self .assertTrue (orphaned .topic is None )
275278 orphaned .delete ()
0 commit comments