add test and fix for timer_intermediate_catch_event

This commit is contained in:
burnettk 2022-09-20 17:23:07 -04:00
parent adbc521cf0
commit a2b81ac8b4
4 changed files with 120 additions and 41 deletions

View File

@ -719,52 +719,59 @@ class ProcessInstanceProcessor:
"""Queue_waiting_receive_messages."""
waiting_tasks = self.get_all_waiting_tasks()
for waiting_task in waiting_tasks:
if waiting_task.task_spec.__class__.__name__ in [
# if it's not something that can wait for a message, skip it
if waiting_task.task_spec.__class__.__name__ not in [
"IntermediateCatchEvent",
"ReceiveTask",
]:
message_model = MessageModel.query.filter_by(
name=waiting_task.task_spec.event_definition.name
).first()
if message_model is None:
raise ApiError(
"invalid_message_name",
f"Invalid message name: {waiting_task.task_spec.event_definition.name}.",
)
continue
message_instance = MessageInstanceModel(
process_instance_id=self.process_instance_model.id,
message_type="receive",
message_model_id=message_model.id,
# timer events are not related to messaging, so ignore them for these purposes
if waiting_task.task_spec.event_definition.__class__.__name__ in [
"TimerEventDefinition",
]:
continue
message_model = MessageModel.query.filter_by(
name=waiting_task.task_spec.event_definition.name
).first()
if message_model is None:
raise ApiError(
"invalid_message_name",
f"Invalid message name: {waiting_task.task_spec.event_definition.name}.",
)
db.session.add(message_instance)
for (
spiff_correlation_property
) in waiting_task.task_spec.event_definition.correlation_properties:
# NOTE: we may have to cycle through keys here
# not sure yet if it's valid for a property to be associated with multiple keys
correlation_key_name = spiff_correlation_property.correlation_keys[
0
]
message_correlation = (
MessageCorrelationModel.query.filter_by(
process_instance_id=self.process_instance_model.id,
name=correlation_key_name,
)
.join(MessageCorrelationPropertyModel)
.filter_by(identifier=spiff_correlation_property.name)
.first()
)
message_correlation_message_instance = (
MessageCorrelationMessageInstanceModel(
message_instance_id=message_instance.id,
message_correlation_id=message_correlation.id,
)
)
db.session.add(message_correlation_message_instance)
message_instance = MessageInstanceModel(
process_instance_id=self.process_instance_model.id,
message_type="receive",
message_model_id=message_model.id,
)
db.session.add(message_instance)
db.session.commit()
for (
spiff_correlation_property
) in waiting_task.task_spec.event_definition.correlation_properties:
# NOTE: we may have to cycle through keys here
# not sure yet if it's valid for a property to be associated with multiple keys
correlation_key_name = spiff_correlation_property.correlation_keys[0]
message_correlation = (
MessageCorrelationModel.query.filter_by(
process_instance_id=self.process_instance_model.id,
name=correlation_key_name,
)
.join(MessageCorrelationPropertyModel)
.filter_by(identifier=spiff_correlation_property.name)
.first()
)
message_correlation_message_instance = (
MessageCorrelationMessageInstanceModel(
message_instance_id=message_instance.id,
message_correlation_id=message_correlation.id,
)
)
db.session.add(message_correlation_message_instance)
db.session.commit()
def do_engine_steps(self, exit_at: None = None, save: bool = False) -> None:
"""Do_engine_steps."""

View File

@ -0,0 +1,44 @@
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_96f6665" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-dev">
<bpmn:process id="Process_test_c11_C_1_1_bd2e724" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_109wuuc</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_109wuuc" sourceRef="StartEvent_1" targetRef="Event_1brn88p" />
<bpmn:endEvent id="Event_07oa1s6">
<bpmn:incoming>Flow_0cy1fiy</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0cy1fiy" sourceRef="Event_1brn88p" targetRef="Event_07oa1s6" />
<bpmn:intermediateCatchEvent id="Event_1brn88p" name="30 seconds">
<bpmn:incoming>Flow_109wuuc</bpmn:incoming>
<bpmn:outgoing>Flow_0cy1fiy</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_1al5gzu">
<bpmn:timeDuration xsi:type="bpmn:tFormalExpression">timedelta(seconds=30)</bpmn:timeDuration>
</bpmn:timerEventDefinition>
</bpmn:intermediateCatchEvent>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_test_c11_C_1_1_bd2e724">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_07oa1s6_di" bpmnElement="Event_07oa1s6">
<dc:Bounds x="372" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ou5tgd_di" bpmnElement="Event_1brn88p">
<dc:Bounds x="272" y="159" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="262" y="202" width="57" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_109wuuc_di" bpmnElement="Flow_109wuuc">
<di:waypoint x="215" y="177" />
<di:waypoint x="272" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0cy1fiy_di" bpmnElement="Flow_0cy1fiy">
<di:waypoint x="308" y="177" />
<di:waypoint x="372" y="177" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -188,9 +188,13 @@ class TestMessageService(BaseTest):
process_instance_result = ProcessInstanceModel.query.all()
assert len(process_instance_result) == 3
process_instance_receiver_one = ProcessInstanceModel.query.filter_by(process_model_identifier='message_receiver_one').first()
process_instance_receiver_one = ProcessInstanceModel.query.filter_by(
process_model_identifier="message_receiver_one"
).first()
assert process_instance_receiver_one is not None
process_instance_receiver_two = ProcessInstanceModel.query.filter_by(process_model_identifier='message_receiver_two').first()
process_instance_receiver_two = ProcessInstanceModel.query.filter_by(
process_model_identifier="message_receiver_two"
).first()
assert process_instance_receiver_two is not None
# just make sure it's a different process instance

View File

@ -0,0 +1,24 @@
"""Test_various_bpmn_constructs."""
from flask.app import Flask
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
class TestVariousBpmnConstructs(BaseTest):
"""TestVariousBpmnConstructs."""
def test_running_process_with_timer_intermediate_catch_event(
self, app: Flask, with_db_and_bpmn_file_cleanup: None
) -> None:
"""Test_running_process_with_timer_intermediate_catch_event."""
process_model = load_test_spec(
"timers_intermediate_catch_event",
process_model_source_directory="timer_intermediate_catch_event",
)
process_instance = self.create_process_instance_from_process_model(
process_model
)
processor = ProcessInstanceProcessor(process_instance)
processor.do_engine_steps(save=True)