From b249626433d0558622f96cb11617d05565d72c13 Mon Sep 17 00:00:00 2001 From: Elizabeth Esswein Date: Wed, 13 Jul 2022 10:59:46 -0400 Subject: [PATCH] fix loop reset task to handle multiple subprocess properly --- SpiffWorkflow/bpmn/specs/SubWorkflowTask.py | 4 + SpiffWorkflow/task.py | 2 - tests/SpiffWorkflow/bpmn/TooManyLoopsTest.py | 11 +++ .../SpiffWorkflow/bpmn/data/sub_in_loop.bpmn | 88 +++++++++++++++++++ .../bpmn/data/sub_in_loop_call_activity.bpmn | 38 ++++++++ 5 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 tests/SpiffWorkflow/bpmn/data/sub_in_loop.bpmn create mode 100644 tests/SpiffWorkflow/bpmn/data/sub_in_loop_call_activity.bpmn diff --git a/SpiffWorkflow/bpmn/specs/SubWorkflowTask.py b/SpiffWorkflow/bpmn/specs/SubWorkflowTask.py index 10b4f57de..d47472a5c 100644 --- a/SpiffWorkflow/bpmn/specs/SubWorkflowTask.py +++ b/SpiffWorkflow/bpmn/specs/SubWorkflowTask.py @@ -58,6 +58,10 @@ def _update_hook(self, my_task): if my_task.id not in wf.subprocesses: super()._update_hook(my_task) + def _predict_hook(self, my_task): + # The base Subworkflow task predict doesn't work with the loop reset task + BpmnSpecMixin._predict_hook(self, my_task) + def _on_complete_hook(self, my_task): for child in my_task.children: child.task_spec._update(child) diff --git a/SpiffWorkflow/task.py b/SpiffWorkflow/task.py index 88a285797..f085c530d 100644 --- a/SpiffWorkflow/task.py +++ b/SpiffWorkflow/task.py @@ -332,8 +332,6 @@ def set_children_future(self): if isinstance(self.task_spec,SubWorkflowTask): self.workflow.delete_subprocess(self) - self.children = [] # if we have a call activity, - # force reset of children. if isinstance(self.task_spec, UnstructuredJoin): # go find all of the gateways with the same name as this one, diff --git a/tests/SpiffWorkflow/bpmn/TooManyLoopsTest.py b/tests/SpiffWorkflow/bpmn/TooManyLoopsTest.py index bc3688d95..a1018e0b6 100644 --- a/tests/SpiffWorkflow/bpmn/TooManyLoopsTest.py +++ b/tests/SpiffWorkflow/bpmn/TooManyLoopsTest.py @@ -55,6 +55,17 @@ def test_with_sub_process(self): # hits 20. self.assertEqual(19, self.workflow.last_task.data['counter2']) + def test_with_two_call_activities(self): + spec, subprocess = self.load_workflow_spec('sub_in_loop*.bpmn', 'main') + self.workflow = BpmnWorkflow(spec, subprocess) + self.workflow.do_engine_steps() + for loop in range(3): + ready = self.workflow.get_ready_user_tasks() + ready[0].data = { 'done': True if loop == 3 else False } + ready[0].complete() + self.workflow.refresh_waiting_tasks() + self.workflow.do_engine_steps() + self.save_restore() def suite(): return unittest.TestLoader().loadTestsFromTestCase(TooManyLoopsTest) diff --git a/tests/SpiffWorkflow/bpmn/data/sub_in_loop.bpmn b/tests/SpiffWorkflow/bpmn/data/sub_in_loop.bpmn new file mode 100644 index 000000000..ec8720e0a --- /dev/null +++ b/tests/SpiffWorkflow/bpmn/data/sub_in_loop.bpmn @@ -0,0 +1,88 @@ + + + + + Flow_0nlj5lh + + + Flow_0nlj5lh + Flow_16vai1a + Flow_1lkecht + + + + Flow_1lkecht + Flow_1vci114 + + + + Flow_0iui938 + Flow_0ew7zdi + Flow_16vai1a + + + Flow_0ew7zdi + + + done + + + + Flow_1vci114 + Flow_0iui938 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SpiffWorkflow/bpmn/data/sub_in_loop_call_activity.bpmn b/tests/SpiffWorkflow/bpmn/data/sub_in_loop_call_activity.bpmn new file mode 100644 index 000000000..2af69b3be --- /dev/null +++ b/tests/SpiffWorkflow/bpmn/data/sub_in_loop_call_activity.bpmn @@ -0,0 +1,38 @@ + + + + + Flow_1dbtwxp + + + + Flow_1t99mly + + + + Flow_1dbtwxp + Flow_1t99mly + + + + + + + + + + + + + + + + + + + + + + + +