Skip to content

Commit 2fcd9ee

Browse files
authored
Deflake bigtable and spanner tests. [(#2224)](GoogleCloudPlatform/python-docs-samples#2224)
* Spanner doesn't actually promise the order of the results, so make the assertion work regardless of ordering. * Bigtable might need some more time to scale, so retry the assertion up to 10 times.
1 parent 8ef175a commit 2fcd9ee

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

samples/metricscaler/metricscaler_test.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,27 @@ def test_scale_bigtable():
4646

4747
scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, True)
4848

49-
time.sleep(10)
50-
cluster.reload()
51-
52-
new_node_count = cluster.serve_nodes
53-
assert (new_node_count == (original_node_count + SIZE_CHANGE_STEP))
49+
for n in range(10):
50+
time.sleep(10)
51+
cluster.reload()
52+
new_node_count = cluster.serve_nodes
53+
try:
54+
assert (new_node_count == (original_node_count + SIZE_CHANGE_STEP))
55+
except AssertionError:
56+
if n == 9:
57+
raise
5458

5559
scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, False)
56-
time.sleep(10)
57-
cluster.reload()
58-
final_node_count = cluster.serve_nodes
59-
assert final_node_count == original_node_count
60+
61+
for n in range(10):
62+
time.sleep(10)
63+
cluster.reload()
64+
final_node_count = cluster.serve_nodes
65+
try:
66+
assert final_node_count == original_node_count
67+
except AssertionError:
68+
if n == 9:
69+
raise
6070

6171

6272
# Unit test for logic

0 commit comments

Comments
 (0)