spiff-arena/tests/SpiffWorkflow/bpmn/NITimerDurationBoundaryTest.py
Dan b8d3d5d84b Squashed 'SpiffWorkflow/' changes from 450ef3bcd..98c6294f1
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
2023-01-26 18:17:35 -05:00

76 lines
2.8 KiB
Python

# -*- coding: utf-8 -*-
import unittest
import datetime
import time
from SpiffWorkflow.task import TaskState
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
from tests.SpiffWorkflow.bpmn.BpmnWorkflowTestCase import BpmnWorkflowTestCase
__author__ = 'kellym'
class NITimerDurationTest(BpmnWorkflowTestCase):
"""
Non-Interrupting Timer boundary test
"""
def setUp(self):
spec, subprocesses = self.load_workflow_spec('timer-non-interrupt-boundary.bpmn', 'NonInterruptTimer')
self.workflow = BpmnWorkflow(spec, subprocesses)
def load_spec(self):
return
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):
self.workflow.do_engine_steps()
ready_tasks = self.workflow.get_tasks(TaskState.READY)
event = self.workflow.get_tasks_from_spec_name('Event_0jyy8ao')[0]
self.assertEqual(event.state, TaskState.WAITING)
loopcount = 0
starttime = datetime.datetime.now()
# test bpmn has a timeout of .2s; we should terminate loop before that.
# The subprocess will also wait
while len(self.workflow.get_waiting_tasks()) == 2 and loopcount < 10:
if save_restore:
self.save_restore()
time.sleep(0.1)
ready_tasks = self.workflow.get_tasks(TaskState.READY)
# There should be one ready task until the boundary event fires
self.assertEqual(len(self.workflow.get_ready_user_tasks()), 1)
self.workflow.refresh_waiting_tasks()
self.workflow.do_engine_steps()
loopcount += 1
endtime = datetime.datetime.now()
duration = endtime - starttime
# appropriate time here is .5 seconds due to the .3 seconds that we loop and then
self.assertEqual(duration < datetime.timedelta(seconds=.5), True)
self.assertEqual(duration > datetime.timedelta(seconds=.2), True)
ready_tasks = self.workflow.get_ready_user_tasks()
# Now there should be two.
self.assertEqual(len(ready_tasks), 2)
for task in ready_tasks:
if task.task_spec.name == 'GetReason':
task.data['delay_reason'] = 'Just Because'
elif task.task_spec.name == 'Activity_Work':
task.data['work_done'] = 'Yes'
task.complete()
self.workflow.refresh_waiting_tasks()
self.workflow.do_engine_steps()
self.assertEqual(self.workflow.is_completed(),True)
self.assertEqual(self.workflow.last_task.data, {'work_done': 'Yes', 'delay_reason': 'Just Because'})
def suite():
return unittest.TestLoader().loadTestsFromTestCase(NITimerDurationTest)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())