From: Daniel Arndt Date: Fri, 7 Jul 2023 10:44:36 +0000 (-0300) Subject: Test to validate workflows are run concurrently X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=dfd1ad5e4121e9a74b212b47ee0362ab49677328;p=osm%2FLCM.git Test to validate workflows are run concurrently Change-Id: I3b2296e4eec8e1f982df993cd3af28d53a79c58d Signed-off-by: Daniel Arndt --- diff --git a/osm_lcm/tests/test_vnf_workflows.py b/osm_lcm/tests/test_vnf_workflows.py index 6265e83c..dcb77dee 100644 --- a/osm_lcm/tests/test_vnf_workflows.py +++ b/osm_lcm/tests/test_vnf_workflows.py @@ -203,10 +203,14 @@ async def mock_get_task_queue_raise_exception( @activity.defn(name=GetVnfDescriptor.__name__) -async def mock_get_vnf_descriptor( - get_vnf_descriptor_input: GetVnfDescriptor.Input, -) -> GetVnfDescriptor.Output: - return GetVnfDescriptor.Output(vnfd=sample_vnfd) +class MockGetVnfDescriptor: + def __init__(self, vnfd=sample_vnfd) -> None: + self.vnfd = vnfd + + async def __call__( + self, get_vnf_descriptor_input: GetVnfDescriptor.Input + ) -> GetVnfDescriptor.Output: + return GetVnfDescriptor.Output(vnfd=self.vnfd) @activity.defn(name=GetVnfDescriptor.__name__) @@ -282,6 +286,13 @@ class MockVduInstantiateWorkflow: pass +@workflow.defn(name=VduInstantiateWorkflow.__name__, sandboxed=SANDBOXED) +class MockVduInstantiateWorkflowSlow: + @workflow.run + async def run(self, workflow_input: VduInstantiateWorkflow.Input) -> None: + await asyncio.sleep(0.5) + + @workflow.defn(name=VduInstantiateWorkflow.__name__, sandboxed=SANDBOXED) class MockVduInstantiateWorkflowFailed: @workflow.run @@ -468,7 +479,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -501,7 +512,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -538,7 +549,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -557,6 +568,61 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): call_args = mock_execute_child_workflow.call_args_list[1].kwargs["workflow"] self.assertEquals(call_args, VduInstantiateWorkflow.__name__) + @patch( + "osm_lcm.temporal.vnf_workflows.VnfInstantiateWorkflowImpl._get_vdu_instantiate_input" + ) + @patch( + "temporalio.workflow.execute_child_workflow", + wraps=workflow.execute_child_workflow, + ) + async def test_vnf_instantiate_workflow__successful__executes_child_workflows_concurrently( + self, + mock_execute_child_workflow: CoroutineMock, + mock_get_vdu_instantiate_input, + ): + # Choose a number of child workflows that would take longer to execute than the execution timeout + num_child_workflows = EXECUTION_TIMEOUT.seconds * 2 + 1 + workflows = [ + VnfInstantiateWorkflowImpl, + MockPrepareVnfWorkflow, + MockVduInstantiateWorkflowSlow, + ] + vnfd = { + "vdu": [vdu] * num_child_workflows, + } + activities = [ + mock_get_task_queue, + self.mock_change_vnf_instantiation_state, + self.mock_change_vnf_state, + self.mock_send_notification_for_vnf, + mock_set_vnf_model, + MockGetVnfDescriptor(vnfd), + mock_get_vnf_record, + mock_get_vim_cloud, + ] + + # Set up the return values with a unique workflow ID for each child workflow + mock_get_vdu_instantiate_input.side_effect = [ + ( + sample_vdu_instantiate_input_with_config, + uuid.uuid4().hex, + ) + for _ in range(num_child_workflows) + ] + async with self.env, self.get_worker(self.task_queue, workflows, activities): + await self.execute_workflow() + + self.assertEquals( + mock_execute_child_workflow.call_count, num_child_workflows + 1 + ) + # Check that PrepareVnfWorkflow is executed + call_args = mock_execute_child_workflow.call_args_list[0].kwargs["workflow"] + self.assertEquals(call_args, VnfPrepareWorkflow.__name__) + # Check that VduInstantiateWorkflow is executed + for i in range(1, num_child_workflows + 1): + call_args = mock_execute_child_workflow.call_args_list[i].kwargs["workflow"] + self.assertEquals(call_args, VduInstantiateWorkflow.__name__) + async def test_vnf_instantiate_workflow__activity_change_vnf_instantiation_state_failed__raise_activity_error( self, ): @@ -566,7 +632,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -586,7 +652,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -606,7 +672,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state_exception, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -626,7 +692,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -646,7 +712,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -672,7 +738,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ] @@ -718,7 +784,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record_raise_exception, mock_get_vim_cloud, ] @@ -738,7 +804,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud_raise_exception, ] @@ -760,7 +826,7 @@ class TestVnfInstantiateWorkflow(asynctest.TestCase): self.mock_change_vnf_state, self.mock_send_notification_for_vnf, mock_set_vnf_model, - mock_get_vnf_descriptor, + MockGetVnfDescriptor(), mock_get_vnf_record, mock_get_vim_cloud, ]