From 86a185b44a51d6a3340f09a172261a159685afec Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Tue, 26 May 2020 12:51:43 -0700 Subject: [PATCH] Add wait_for_instance_group_to_reach_expected_size --- tools/run_tests/run_xds_tests.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tools/run_tests/run_xds_tests.py b/tools/run_tests/run_xds_tests.py index 9b47b28d1ba..954bc4a3229 100755 --- a/tools/run_tests/run_xds_tests.py +++ b/tools/run_tests/run_xds_tests.py @@ -582,6 +582,8 @@ def add_instance_group(gcp, zone, name, size): instance_group = InstanceGroup(config['name'], result['instanceGroup'], zone) gcp.instance_groups.append(instance_group) + wait_for_instance_group_to_reach_expected_size(gcp, instance_group, size, + _WAIT_FOR_OPERATION_SEC) return instance_group @@ -936,14 +938,8 @@ def resize_instance_group(gcp, instance_group.zone, result['name'], timeout_sec=360) - start_time = time.time() - while True: - current_size = len(get_instance_names(gcp, instance_group)) - if current_size == new_size: - break - if time.time() - start_time > timeout_sec: - raise Exception('Failed to resize primary instance group') - time.sleep(2) + wait_for_instance_group_to_reach_expected_size(gcp, instance_group, + new_size, timeout_sec) def patch_url_map_backend_service(gcp, backend_service): @@ -962,6 +958,20 @@ def patch_url_map_backend_service(gcp, backend_service): wait_for_global_operation(gcp, result['name']) +def wait_for_instance_group_to_reach_expected_size(gcp, instance_group, + expected_size, timeout_sec): + start_time = time.time() + while True: + current_size = len(get_instance_names(gcp, instance_group)) + if current_size == expected_size: + break + if time.time() - start_time > timeout_sec: + raise Exception( + 'Instance group had expected size %d but actual size %d' % + (expected_size, current_size)) + time.sleep(2) + + def wait_for_global_operation(gcp, operation, timeout_sec=_WAIT_FOR_OPERATION_SEC):