Skip to content
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
2 changes: 1 addition & 1 deletion dotflow/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(

if mode != TypeExecution.BACKGROUND:
self._callback_workflow(tasks=self.tasks)
elif self.config:
else:

def _background_cleanup():
self.thread.join()
Expand Down
55 changes: 55 additions & 0 deletions tests/core/test_workflow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test context of controller"""

import threading
import unittest
from types import FunctionType
from unittest.mock import Mock
Expand Down Expand Up @@ -98,3 +99,57 @@ def test_workflow_with_class_completed(self):

controller = Manager(tasks=[task])
self.assertEqual(controller.tasks[0].status, TypeStatus.COMPLETED)

def test_background_callback_runs_without_config(self):
task = Task(
task_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
step=action_step,
callback=simple_callback,
)
mock_success = Mock()

manager = Manager(
tasks=[task],
mode=TypeExecution.BACKGROUND,
on_success=mock_success,
config=None,
)

for executor in (manager.tasks, getattr(manager, "thread", None)):
if hasattr(executor, "join"):
executor.join(timeout=5)

for thread in list(threading.enumerate()):
if thread is threading.current_thread():
continue
if not thread.daemon:
continue
thread.join(timeout=5)

mock_success.assert_called()

def test_background_callback_failure_runs_without_config(self):
task = Task(
task_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
step=action_step_with_error,
callback=simple_callback,
)
mock_failure = Mock()

manager = Manager(
tasks=[task],
mode=TypeExecution.BACKGROUND,
on_failure=mock_failure,
config=None,
)

if hasattr(manager, "thread"):
manager.thread.join(timeout=5)
for thread in list(threading.enumerate()):
if thread is threading.current_thread():
continue
if not thread.daemon:
continue
thread.join(timeout=5)

mock_failure.assert_called()
Loading