From e1f4d7fca269c468f27934d373c815e4b75ab63f Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 7 Feb 2018 20:22:24 -0500 Subject: [PATCH] Fix races in conditionals tests In convergence, resources have a tendency to appear and disappear in their own time, not atomically with a change to the stack state. Therefore when testing conditionals (i.e. looking for resources to appear/disappear) we must be careful to take into account the states of the resources we find to avoid race conditions. Change-Id: I488921c6c4c3324912ded494db5ab9605becce9b Closes-Bug: #1737796 --- heat_integrationtests/common/test.py | 5 +++-- heat_integrationtests/functional/test_conditions.py | 6 ++++-- heat_integrationtests/functional/test_create_update.py | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/heat_integrationtests/common/test.py b/heat_integrationtests/common/test.py index 88988ec480..86d7d0a55d 100644 --- a/heat_integrationtests/common/test.py +++ b/heat_integrationtests/common/test.py @@ -520,9 +520,10 @@ class HeatIntegrationTest(testscenarios.WithScenarios, return self.list_resources(nested_identifier) return self.client.resources.list(nested_identifier) - def list_resources(self, stack_identifier): + def list_resources(self, stack_identifier, filter_func=None): resources = self.client.resources.list(stack_identifier) - return dict((r.resource_name, r.resource_type) for r in resources) + return dict((r.resource_name, r.resource_type) for r in resources + if (filter_func(r) if callable(filter_func) else True)) def get_resource_stack_id(self, r): stack_link = [l for l in r.links if l.get('rel') == 'stack'][0] diff --git a/heat_integrationtests/functional/test_conditions.py b/heat_integrationtests/functional/test_conditions.py index ebb3c0829e..9feb7cd2c3 100644 --- a/heat_integrationtests/functional/test_conditions.py +++ b/heat_integrationtests/functional/test_conditions.py @@ -309,7 +309,8 @@ class CreateUpdateResConditionTest(functional_base.FunctionalTestsBase): def res_assert_for_prod(self, resources, bj_prod=True, fj_zone=False, shannxi_provice=False): - res_names = [res.resource_name for res in resources] + res_names = {res.resource_name for res in resources + if res.resource_status != 'DELETE_COMPLETE'} if bj_prod: self.assertEqual(4, len(resources)) self.assertIn('beijing_prod_res', res_names) @@ -331,7 +332,8 @@ class CreateUpdateResConditionTest(functional_base.FunctionalTestsBase): def res_assert_for_test(self, resources, fj_zone=False, shannxi_provice=False): - res_names = [res.resource_name for res in resources] + res_names = {res.resource_name for res in resources + if res.resource_status != 'DELETE_COMPLETE'} if fj_zone: self.assertEqual(4, len(resources)) diff --git a/heat_integrationtests/functional/test_create_update.py b/heat_integrationtests/functional/test_create_update.py index 3d4ca76487..29a094d247 100644 --- a/heat_integrationtests/functional/test_create_update.py +++ b/heat_integrationtests/functional/test_create_update.py @@ -701,7 +701,11 @@ resources: expected_status='UPDATE_IN_PROGRESS') def check_resources(): - resources = self.list_resources(stack_identifier) + def is_complete(r): + return r.resource_status in {'CREATE_COMPLETE', + 'UPDATE_COMPLETE'} + + resources = self.list_resources(stack_identifier, is_complete) if len(resources) < 2: return False self.assertIn('test3', resources)