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
changes/17/541917/2
Zane Bitter 5 years ago
parent 5d4bd6f730
commit e1f4d7fca2
  1. 5
      heat_integrationtests/common/test.py
  2. 6
      heat_integrationtests/functional/test_conditions.py
  3. 6
      heat_integrationtests/functional/test_create_update.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]

@ -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))

@ -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)

Loading…
Cancel
Save