Add unit test for nested stack cancel

Test that when cancelling a nested stack, its children also get
cancelled.

Change-Id: Icfd4ef1654dd141d17541bed48fee412001efdec
This commit is contained in:
Zane Bitter 2019-10-29 15:10:55 -04:00
parent 8cd6a06736
commit 38614a78c1
2 changed files with 26 additions and 0 deletions

View File

@ -110,6 +110,9 @@ class WorkerService(object):
Marks the stack as FAILED due to cancellation, but, allows all
in_progress resources to complete normally; no worker is stopped
abruptly.
Any in-progress traversals are also stopped on all nested stacks that
are descendants of the one passed.
"""
_stop_traversal(stack)

View File

@ -197,6 +197,29 @@ class WorkerServiceTest(common.HeatTestCase):
self.assertEqual('stack1', call_args1.name)
self.assertEqual('stack2', call_args2.name)
@mock.patch.object(worker, '_stop_traversal')
def test_stop_nested_traversal_stops_deeply_nested_stack(self, mock_st):
mock_tgm = mock.Mock()
ctx = utils.dummy_context()
tmpl = templatem.Template.create_empty_template()
stack1 = parser.Stack(ctx, 'stack1', tmpl,
current_traversal='123')
stack1.store()
stack2 = parser.Stack(ctx, 'stack2', tmpl,
owner_id=stack1.id, current_traversal='456')
stack2.store()
stack3 = parser.Stack(ctx, 'stack3', tmpl,
owner_id=stack2.id, current_traversal='789')
stack3.store()
_worker = worker.WorkerService('host-1', 'topic-1', 'engine-001',
mock_tgm)
_worker.stop_traversal(stack2)
self.assertEqual(2, mock_st.call_count)
call1, call2 = mock_st.call_args_list
call_args1, call_args2 = call1[0][0], call2[0][0]
self.assertEqual('stack2', call_args1.name)
self.assertEqual('stack3', call_args2.name)
@mock.patch.object(worker, '_cancel_workers')
@mock.patch.object(worker.WorkerService, 'stop_traversal')
def test_stop_all_workers_when_stack_in_progress(self, mock_st, mock_cw):