From f9ee0e0746711a07badb2aae00291ca2a803969c Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Wed, 9 Oct 2013 15:41:07 +0100 Subject: [PATCH] Fix possible race issue with test_engine_service There's the potential for racy behavior in test_show_watch, because the result of show_watch(self.ctx, watch_name=None) is all watches visible to the user, not only those for a specific stack. So it's possible that the result length will be more than two, and since the watch name is also not unique, we could see spurious test failures. So make the test assertions more specific, and avoid reusing the same watch name in test_show_watch_metric. Change-Id: Ibb1cbae04dee4b6c4ada44336143fd122a3cb53f Closes-Bug: #1237324 --- heat/tests/test_engine_service.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index f6a104406c..0b433bdad1 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -1577,7 +1577,7 @@ class StackServiceTest(HeatTestCase): u'MetricName': u'ServiceFailure'} self.wr = [] self.wr.append(watchrule.WatchRule(context=self.ctx, - watch_name='HttpFailureAlarm', + watch_name='show_watch_1', rule=rule, watch_data=[], stack_id=self.stack.id, @@ -1585,20 +1585,28 @@ class StackServiceTest(HeatTestCase): self.wr[0].store() self.wr.append(watchrule.WatchRule(context=self.ctx, - watch_name='AnotherWatch', + watch_name='show_watch_2', rule=rule, watch_data=[], stack_id=self.stack.id, state='NORMAL')) self.wr[1].store() - # watch_name=None should return both watches + # watch_name=None should return all watches result = self.eng.show_watch(self.ctx, watch_name=None) - self.assertEqual(2, len(result)) + result_names = [r.get('name') for r in result] + self.assertIn('show_watch_1', result_names) + self.assertIn('show_watch_2', result_names) - # watch_name="HttpFailureAlarm" should return only one - result = self.eng.show_watch(self.ctx, watch_name="HttpFailureAlarm") + result = self.eng.show_watch(self.ctx, watch_name="show_watch_1") self.assertEqual(1, len(result)) + self.assertIn('name', result[0]) + self.assertEqual('show_watch_1', result[0]['name']) + + result = self.eng.show_watch(self.ctx, watch_name="show_watch_2") + self.assertEqual(1, len(result)) + self.assertIn('name', result[0]) + self.assertEqual('show_watch_2', result[0]['name']) self.assertRaises(exception.WatchRuleNotFound, self.eng.show_watch, @@ -1622,7 +1630,7 @@ class StackServiceTest(HeatTestCase): u'Threshold': u'2', u'MetricName': u'ServiceFailure'} self.wr = watchrule.WatchRule(context=self.ctx, - watch_name='HttpFailureAlarm', + watch_name='show_watch_metric_1', rule=rule, watch_data=[], stack_id=self.stack.id, @@ -1630,7 +1638,7 @@ class StackServiceTest(HeatTestCase): self.wr.store() # And add a metric datapoint - watch = db_api.watch_rule_get_by_name(self.ctx, "HttpFailureAlarm") + watch = db_api.watch_rule_get_by_name(self.ctx, 'show_watch_metric_1') self.assertNotEqual(watch, None) values = {'watch_rule_id': watch.id, 'data': {u'Namespace': u'system/linux',