mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-02-11 17:07:18 +00:00
98c6294f1 Merge pull request #287 from sartography/feature/workflow_data_exceptions d40a1da59 Workflow Data Exceptions were broken in the previous error refactor. This assures we are getting good messages from these errors. a156378e1 Merge pull request #286 from sartography/feature/inclusive-gateway-support 7f6e398c2 bypass unnecessary checks in gateway joins ade21a894 revert a few things e1cf75202 Merge branch 'main' into feature/inclusive-gateway-support 15a0a4414 revert change to MultiChoice and handle no defaults in BPMN specs e1469e6bb add support for diverging inclusive gateways 71fd86386 really prevent non-default flows without conditions 924759d9b clean up join specs 7378639d3 Merge pull request #284 from sartography/feature/improved-timer-events dc8d139d2 remove useless method 530f23697 Merge branch 'main' into feature/improved-timer-events 307cca9c5 partially clean up existing gateways 0a344285e clean up task parsers 2cef997d1 add waiting_events method to bpmn workflow 48091c407 serializer migration script and miscellaneous fixes to serialization 61316854b store internal timer data as string/float 389c14c4c add some tests for parsing durations 582bc9482 convert timers to iso 8601 6dfd7ebe9 remove extraneous calls to update 6bd429529 clean up tests d56e9912f remove useless method git-subtree-dir: SpiffWorkflow git-subtree-split: 98c6294f1240aee599cd98bcee58d121cb57b331
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import datetime
|
|
import unittest
|
|
import time
|
|
|
|
from SpiffWorkflow.bpmn.PythonScriptEngine import PythonScriptEngine
|
|
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
|
|
from tests.SpiffWorkflow.bpmn.BpmnWorkflowTestCase import BpmnWorkflowTestCase
|
|
|
|
__author__ = 'kellym'
|
|
|
|
# the data doesn't really propagate to the end as in a 'normal' workflow, so I call a
|
|
# custom function that records the number of times this got called so that
|
|
# we can keep track of how many times the triggered item gets called.
|
|
counter = 0
|
|
def my_custom_function():
|
|
global counter
|
|
counter = counter+1
|
|
return counter
|
|
|
|
class CustomScriptEngine(PythonScriptEngine):
|
|
"""This is a custom script processor that can be easily injected into Spiff Workflow.
|
|
It will execute python code read in from the bpmn. It will also make any scripts in the
|
|
scripts directory available for execution. """
|
|
def __init__(self):
|
|
augment_methods = {
|
|
'custom_function': my_custom_function,
|
|
'timedelta': datetime.timedelta,
|
|
}
|
|
super().__init__(scripting_additions=augment_methods)
|
|
|
|
|
|
class TimerCycleStartTest(BpmnWorkflowTestCase):
|
|
|
|
def setUp(self):
|
|
self.spec, self.subprocesses = self.load_workflow_spec('timer-cycle-start.bpmn', 'timer')
|
|
self.workflow = BpmnWorkflow(self.spec, self.subprocesses, script_engine=CustomScriptEngine())
|
|
|
|
def testRunThroughHappy(self):
|
|
self.actual_test(save_restore=False)
|
|
|
|
def testThroughSaveRestore(self):
|
|
self.actual_test(save_restore=True)
|
|
|
|
def actual_test(self,save_restore = False):
|
|
global counter
|
|
counter = 0
|
|
# We have a loop so we can continue to execute waiting tasks when
|
|
# timers expire. The test workflow has a wait timer that pauses long enough to
|
|
# allow the cycle to complete three times before being cancelled by the terminate
|
|
# event (the timer should only run twice, we want to make sure it doesn't keep
|
|
# executing)
|
|
for loopcount in range(6):
|
|
self.workflow.do_engine_steps()
|
|
if save_restore:
|
|
self.save_restore()
|
|
self.workflow.script_engine = CustomScriptEngine()
|
|
time.sleep(0.1)
|
|
self.workflow.refresh_waiting_tasks()
|
|
|
|
self.assertEqual(counter, 2)
|
|
self.assertTrue(self.workflow.is_completed())
|
|
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromTestCase(TimerCycleStartTest)
|
|
if __name__ == '__main__':
|
|
unittest.TextTestRunner(verbosity=2).run(suite())
|