Skip to content

Commit b3ca070

Browse files
committed
Address review comments. (Will be squashed.)
1 parent 36bf958 commit b3ca070

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

system_tests/bigtable.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ class Config(object):
4444
CLUSTER = None
4545

4646

47+
def _operation_wait(operation, max_attempts=5):
48+
"""Wait until an operation has completed.
49+
50+
:type operation: :class:`gcloud.bigtable.cluster.Operation`
51+
:param operation: Operation that has not finished.
52+
53+
:type max_attempts: int
54+
:param max_attempts: (Optional) The maximum number of times to check if
55+
the operation has finished. Defaults to 5.
56+
"""
57+
total_sleep = 0
58+
while not operation.finished():
59+
if total_sleep > max_attempts:
60+
return False
61+
time.sleep(1)
62+
total_sleep += 1
63+
64+
return True
65+
66+
4767
def setUpModule():
4868
Config.CLIENT = Client(admin=True)
4969
Config.CLUSTER = Config.CLIENT.cluster(CENTRAL_1C_ZONE, CLUSTER_ID,
@@ -58,12 +78,8 @@ def setUpModule():
5878

5979
# After listing, create the test cluster.
6080
created_op = Config.CLUSTER.create()
61-
total_sleep = 0
62-
while not created_op.finished():
63-
if total_sleep > 5:
64-
raise RuntimeError('Cluster creation exceed 5 seconds.')
65-
time.sleep(1)
66-
total_sleep += 1
81+
if not _operation_wait(created_op):
82+
raise RuntimeError('Cluster creation exceed 5 seconds.')
6783

6884

6985
def tearDownModule():
@@ -95,7 +111,8 @@ def test_list_clusters(self):
95111
self.assertTrue(cluster_existence)
96112

97113
def test_reload(self):
98-
# Use same arguments as Config.CLUSTER (created in `setUpModule`).
114+
# Use same arguments as Config.CLUSTER (created in `setUpModule`)
115+
# so we can use reload() on a fresh instance.
99116
cluster = Config.CLIENT.cluster(CENTRAL_1C_ZONE, CLUSTER_ID)
100117
# Make sure metadata unset before reloading.
101118
cluster.display_name = None
@@ -113,8 +130,7 @@ def test_create_cluster(self):
113130
self.clusters_to_delete.append(cluster)
114131

115132
# We want to make sure the operation completes.
116-
time.sleep(2)
117-
self.assertTrue(operation.finished())
133+
self.assertTrue(_operation_wait(operation))
118134

119135
# Create a new cluster instance and make sure it is the same.
120136
cluster_alt = Config.CLIENT.cluster(CENTRAL_1C_ZONE, cluster_id)

0 commit comments

Comments
 (0)