Merge "Fix DBDeadlock error in stack update"

This commit is contained in:
Jenkins 2016-05-16 03:04:17 +00:00 committed by Gerrit Code Review
commit b2fceba633
2 changed files with 11 additions and 0 deletions

View File

@ -530,6 +530,8 @@ def stack_create(context, values):
return stack_ref return stack_ref
@oslo_db_api.wrap_db_retry(max_retries=3, retry_on_deadlock=True,
retry_interval=0.5, inc_retry_interval=True)
def stack_update(context, stack_id, values, exp_trvsl=None): def stack_update(context, stack_id, values, exp_trvsl=None):
stack = stack_get(context, stack_id) stack = stack_get(context, stack_id)

View File

@ -1750,6 +1750,15 @@ class DBAPIStackTest(common.HeatTestCase):
exp_trvsl=diff_uuid) exp_trvsl=diff_uuid)
self.assertFalse(updated) self.assertFalse(updated)
@mock.patch.object(time, 'sleep')
def test_stack_update_retries_on_deadlock(self, sleep):
stack = create_stack(self.ctx, self.template, self.user_creds)
with mock.patch('sqlalchemy.orm.query.Query.update',
side_effect=db_exception.DBDeadlock) as mock_update:
self.assertRaises(db_exception.DBDeadlock,
db_api.stack_update, self.ctx, stack.id, {})
self.assertEqual(4, mock_update.call_count)
def test_stack_set_status_release_lock(self): def test_stack_set_status_release_lock(self):
stack = create_stack(self.ctx, self.template, self.user_creds) stack = create_stack(self.ctx, self.template, self.user_creds)
values = { values = {