From 2fcd9ee70f3dbf21753e167941d2f9b2ed41c5fa Mon Sep 17 00:00:00 2001 From: Thea Flowers Date: Fri, 14 Jun 2019 14:28:27 -0700 Subject: [PATCH] Deflake bigtable and spanner tests. [(#2224)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/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. --- samples/metricscaler/metricscaler_test.py | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/samples/metricscaler/metricscaler_test.py b/samples/metricscaler/metricscaler_test.py index f4a18b841..51077cee5 100644 --- a/samples/metricscaler/metricscaler_test.py +++ b/samples/metricscaler/metricscaler_test.py @@ -46,17 +46,27 @@ def test_scale_bigtable(): scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, True) - time.sleep(10) - cluster.reload() - - new_node_count = cluster.serve_nodes - assert (new_node_count == (original_node_count + SIZE_CHANGE_STEP)) + for n in range(10): + time.sleep(10) + cluster.reload() + new_node_count = cluster.serve_nodes + try: + assert (new_node_count == (original_node_count + SIZE_CHANGE_STEP)) + except AssertionError: + if n == 9: + raise scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, False) - time.sleep(10) - cluster.reload() - final_node_count = cluster.serve_nodes - assert final_node_count == original_node_count + + for n in range(10): + time.sleep(10) + cluster.reload() + final_node_count = cluster.serve_nodes + try: + assert final_node_count == original_node_count + except AssertionError: + if n == 9: + raise # Unit test for logic