async def test(): tmpl = TEMPLATES['task_timeout'] wflow = Workflow(WorkflowTemplate.from_dict(tmpl)) wflow.run({'initial': 'data'}) # The workflow is OK await wflow self.assertEqual(FutureState.get(wflow), FutureState.finished) # The task has timed out task = wflow._tasks_by_id.get('1') with self.assertRaises(asyncio.CancelledError): task.exception() self.assertEqual(FutureState.get(task), FutureState.timeout)
async def test(): tmpl = TEMPLATES['ok'] wflow = Workflow(WorkflowTemplate.from_dict(tmpl)) wflow.run({'initial': 'data'}) await wflow # These tasks have finished for tid in tmpl['graph'].keys(): task = wflow._tasks_by_id.get(tid) self.assertTrue(task.done()) self.assertEqual(FutureState.get(task), FutureState.finished) # The workflow finished properly self.assertTrue(wflow.done()) self.assertEqual(FutureState.get(wflow), FutureState.finished)
async def test(): tmpl = TEMPLATES['workflow_cancel'] wflow = Workflow(WorkflowTemplate.from_dict(tmpl)) wflow.run({'initial': 'data'}) # Workflow is cancelled with self.assertRaises(asyncio.CancelledError): await wflow self.assertEqual(FutureState.get(wflow), FutureState.cancelled) # This task was cancelled task = wflow._tasks_by_id.get('cancel') with self.assertRaises(asyncio.CancelledError): task.exception() self.assertEqual(FutureState.get(task), FutureState.cancelled) # These tasks were never started for tid in ('2', '3', '4'): task = wflow._tasks_by_id.get(tid) self.assertIs(task, None)
async def test(): tmpl = TEMPLATES['crash_test'] # Test crash at task __init__ wflow = Workflow(WorkflowTemplate.from_dict(tmpl)) wflow.run({'initial': 'data'}) await wflow # These tasks have finished for tid in ('1', '2'): task = wflow._tasks_by_id.get(tid) self.assertTrue(task.done()) self.assertEqual(FutureState.get(task), FutureState.finished) # These tasks were never started for tid in ('crash', 'wont_run'): task = wflow._tasks_by_id.get(tid) self.assertIs(task, None) # The workflow finished properly self.assertTrue(wflow.done()) self.assertEqual(FutureState.get(wflow), FutureState.finished) # Test crash inside a task tmpl['tasks'][0]['config'] = {'init_ok': None} wflow = Workflow(WorkflowTemplate.from_dict(tmpl)) wflow.run({'initial': 'data'}) await wflow # These tasks have finished for tid in ('1', '2'): task = wflow._tasks_by_id.get(tid) self.assertTrue(task.done()) self.assertEqual(FutureState.get(task), FutureState.finished) # This task crashed during execution task = wflow._tasks_by_id.get('crash') self.assertTrue(task.done()) self.assertEqual(FutureState.get(task), FutureState.exception) # This task was never started task = wflow._tasks_by_id.get('wont_run') self.assertIs(task, None) # The workflow finished properly self.assertTrue(wflow.done()) self.assertEqual(FutureState.get(wflow), FutureState.finished)