Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loop reset task to handle multiple subprocess properly #192

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SpiffWorkflow/bpmn/specs/SubWorkflowTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions SpiffWorkflow/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/SpiffWorkflow/bpmn/TooManyLoopsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
88 changes: 88 additions & 0 deletions tests/SpiffWorkflow/bpmn/data/sub_in_loop.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0hx6iqe" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
<bpmn:process id="main" name="Main" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0nlj5lh</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="initialize" name="Initialize">
<bpmn:incoming>Flow_0nlj5lh</bpmn:incoming>
<bpmn:incoming>Flow_16vai1a</bpmn:incoming>
<bpmn:outgoing>Flow_1lkecht</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1lkecht" sourceRef="initialize" targetRef="subprocess_in_loop" />
<bpmn:callActivity id="subprocess_in_loop" name="Subprocess in Loop" calledElement="subprocess">
<bpmn:incoming>Flow_1lkecht</bpmn:incoming>
<bpmn:outgoing>Flow_1vci114</bpmn:outgoing>
</bpmn:callActivity>
<bpmn:sequenceFlow id="Flow_1vci114" sourceRef="subprocess_in_loop" targetRef="call_2" />
<bpmn:exclusiveGateway id="Gateway_158gdvg" default="Flow_16vai1a">
<bpmn:incoming>Flow_0iui938</bpmn:incoming>
<bpmn:outgoing>Flow_0ew7zdi</bpmn:outgoing>
<bpmn:outgoing>Flow_16vai1a</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:endEvent id="Event_0l6q7ei">
<bpmn:incoming>Flow_0ew7zdi</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0ew7zdi" sourceRef="Gateway_158gdvg" targetRef="Event_0l6q7ei">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">done</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="Flow_0iui938" sourceRef="call_2" targetRef="Gateway_158gdvg" />
<bpmn:callActivity id="call_2" name="Call Subprocess again" calledElement="subprocess">
<bpmn:incoming>Flow_1vci114</bpmn:incoming>
<bpmn:outgoing>Flow_0iui938</bpmn:outgoing>
</bpmn:callActivity>
<bpmn:sequenceFlow id="Flow_0nlj5lh" sourceRef="StartEvent_1" targetRef="initialize" />
<bpmn:sequenceFlow id="Flow_16vai1a" sourceRef="Gateway_158gdvg" targetRef="initialize" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="main">
<bpmndi:BPMNEdge id="Flow_1lkecht_di" bpmnElement="Flow_1lkecht">
<di:waypoint x="350" y="117" />
<di:waypoint x="420" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1vci114_di" bpmnElement="Flow_1vci114">
<di:waypoint x="520" y="117" />
<di:waypoint x="580" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0ew7zdi_di" bpmnElement="Flow_0ew7zdi">
<di:waypoint x="785" y="117" />
<di:waypoint x="862" y="117" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1104" y="159" width="60" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0iui938_di" bpmnElement="Flow_0iui938">
<di:waypoint x="680" y="117" />
<di:waypoint x="735" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0nlj5lh_di" bpmnElement="Flow_0nlj5lh">
<di:waypoint x="188" y="117" />
<di:waypoint x="250" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_16vai1a_di" bpmnElement="Flow_16vai1a">
<di:waypoint x="760" y="142" />
<di:waypoint x="760" y="240" />
<di:waypoint x="300" y="240" />
<di:waypoint x="300" y="157" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Activity_0721i5u_di" bpmnElement="initialize">
<dc:Bounds x="250" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1lcptwy_di" bpmnElement="call_2">
<dc:Bounds x="580" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="152" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1stre5m_di" bpmnElement="subprocess_in_loop">
<dc:Bounds x="420" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_158gdvg_di" bpmnElement="Gateway_158gdvg" isMarkerVisible="true">
<dc:Bounds x="735" y="92" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0l6q7ei_di" bpmnElement="Event_0l6q7ei">
<dc:Bounds x="862" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
38 changes: 38 additions & 0 deletions tests/SpiffWorkflow/bpmn/data/sub_in_loop_call_activity.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0vwjlip" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
<bpmn:process id="subprocess" name="Subprocess" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1dbtwxp</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1dbtwxp" sourceRef="StartEvent_1" targetRef="Activity_1g5e8v7" />
<bpmn:endEvent id="Event_1ukgnws">
<bpmn:incoming>Flow_1t99mly</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1t99mly" sourceRef="Activity_1g5e8v7" targetRef="Event_1ukgnws" />
<bpmn:task id="Activity_1g5e8v7" name="Subprocess Task">
<bpmn:incoming>Flow_1dbtwxp</bpmn:incoming>
<bpmn:outgoing>Flow_1t99mly</bpmn:outgoing>
</bpmn:task>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="subprocess">
<bpmndi:BPMNEdge id="Flow_1dbtwxp_di" bpmnElement="Flow_1dbtwxp">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1t99mly_di" bpmnElement="Flow_1t99mly">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ukgnws_di" bpmnElement="Event_1ukgnws">
<dc:Bounds x="432" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0hql87y_di" bpmnElement="Activity_1g5e8v7">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>