Skip to content

Commit

Permalink
Fixed event names in tests and callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Tervala authored and Justin Tervala committed Apr 26, 2017
1 parent a412efa commit 596af45
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 54 deletions.
30 changes: 15 additions & 15 deletions core/case/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,48 +108,48 @@ def __construct_logging_signal(event_type, message_name, entry_message):
'Workflow Execution Start',
'Workflow execution started')
AppInstanceCreated, __app_instance_created_callback = __construct_logging_signal('Workflow',
'InstanceCreated',
'App Instance Created',
'New app instance created')
StepExecutionSuccess, __step_execution_success_callback = __construct_logging_signal('Workflow',
'StepExecutionSuccess',
'Step Execution Success',
'Step executed successfully')
StepExecutionError, __step_execution_error_callback = __construct_logging_signal('Workflow',
'StepExecutionError',
'Step Execution Error',
'Step executed with error')
NextStepFound, __next_step_found_callback = __construct_logging_signal('Workflow', 'NextStepFound', 'Next step found')
NextStepFound, __next_step_found_callback = __construct_logging_signal('Workflow', 'Next Step Found', 'Next step found')

WorkflowShutdown, __workflow_shutdown_callback = __construct_logging_signal('Workflow',
'WorkflowShutdown',
'Workflow Shutdown',
'Workflow shutdown')

# Step callbacks

FunctionExecutionSuccess, __func_exec_success_callback = __construct_logging_signal('Step',
'FunctionExecutionSuccess',
'Function Execution Success',
'Function executed successfully')

StepInputValidated, __step_input_validated_callback = __construct_logging_signal('Step',
'InputValidated',
'Input Validated',
'Input successfully validated')
StepInputInvalid, __step_input_invalid_callback = __construct_logging_signal('Step',
'InputInvalid',
'Input Invalid',
'Input is invalid')
ConditionalsExecuted, __conditionals_executed_callback = __construct_logging_signal('Step',
'ConditionalsExecuted',
'Conditionals Executed',
'Conditionals executed')

# Next step callbacks
NextStepTaken, __next_step_taken_callback = __construct_logging_signal('Next Step', 'NextStepTaken', 'Next step taken')
NextStepTaken, __next_step_taken_callback = __construct_logging_signal('Next Step', 'Next Step Taken', 'Next step taken')
NextStepNotTaken, __next_step_not_taken_callback = __construct_logging_signal('Next Step',
'NextStepNotTaken',
'Next Step Not Taken',
'Next step not taken')

# Flag callbacks
FlagArgsValid, __flag_args_valid_callback = __construct_logging_signal('Flag', 'FlagArgsValid', 'Flag arguments valid')
FlagArgsValid, __flag_args_valid_callback = __construct_logging_signal('Flag', 'Flag Arguments Valid', 'Flag arguments valid')
FlagArgsInvalid, __flag_args_invalid_callback = __construct_logging_signal('Flag',
'FlagArgsInvalid',
'Flag Arguments Invalid',
'Flag arguments invalid')

# Filter callbacks
FilterSuccess, __filter_success_callback = __construct_logging_signal('Filter', 'FilterSuccess', 'Filter success')
FilterError, __filter_error_callback = __construct_logging_signal('Filter', 'FilterError', 'Filter error')
FilterSuccess, __filter_success_callback = __construct_logging_signal('Filter', 'Filter Success', 'Filter success')
FilterError, __filter_error_callback = __construct_logging_signal('Filter', 'Filter Error', 'Filter error')
18 changes: 9 additions & 9 deletions core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ def execute_workflow(self, playbook_name, workflow_name, start='start'):
global threading_is_initialized

key = _WorkflowKey(playbook_name, workflow_name)
workflow = self.workflows[key]
subs = deepcopy(subscription.subscriptions)

# If threading has not been initialized, initialize it.
if not threading_is_initialized:
initialize_threading()

workflows.append(pool.submit(execute_workflow_worker, workflow, start, subs))
callbacks.SchedulerJobExecuted.send(self)
if key in self.workflows:
workflow = self.workflows[key]
subs = deepcopy(subscription.subscriptions)

# If threading has not been initialized, initialize it.
if not threading_is_initialized:
initialize_threading()
workflows.append(pool.submit(execute_workflow_worker, workflow, start, subs))
callbacks.SchedulerJobExecuted.send(self)

def get_workflow(self, playbook_name, workflow_name):
key = _WorkflowKey(playbook_name, workflow_name)
Expand Down
3 changes: 2 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
'test_instance',
'test_controller',
'test_widget_signals',
'test_metrics']
'test_metrics',
'test_metrics_server']
4 changes: 2 additions & 2 deletions tests/suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def add_tests_to_suite(suite, test_modules):
add_tests_to_suite(case_suite, __case_tests)

__server_tests = [test_case_server, test_triggers, test_users_and_roles, test_server,
test_apps_and_devices, test_workflow_server, test_app_blueprint, test_metrics]
test_apps_and_devices, test_workflow_server, test_app_blueprint, test_metrics_server]
server_suite = TestSuite()
add_tests_to_suite(server_suite, __server_tests)

__execution_tests = [test_execution_runtime, test_execution_element, test_execution_events, test_execution_modes,
test_step, test_helper_functions, test_filter, test_argument, test_flag, test_next_step,
test_scheduler_actions, test_instance, test_controller, test_widget_signals]
test_scheduler_actions, test_instance, test_controller, test_widget_signals, test_metrics]
execution_suite = TestSuite()
add_tests_to_suite(execution_suite, __execution_tests)

Expand Down
48 changes: 24 additions & 24 deletions tests/test_execution_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_workflowExecutionEvents(self):
subs = {'testExecutionEventsController':
Subscription(subscriptions=
{workflow_name:
Subscription(events=["InstanceCreated", "StepExecutionSuccess",
"NextStepFound", "WorkflowShutdown"])})}
Subscription(events=["App Instance Created", "Step Execution Success",
"Next Step Found", "Workflow Shutdown"])})}

case_subscription.set_subscriptions(
{'testExecutionEvents': case_subscription.CaseSubscriptions(subscriptions=subs)})
Expand Down Expand Up @@ -61,8 +61,8 @@ def test_stepExecutionEvents(self):
Subscription(subscriptions=
{'start':
Subscription(
events=["FunctionExecutionSuccess", "InputValidated",
"ConditionalsExecuted"])})})}
events=["Function Execution Success", "Input Validated",
"Conditionals Executed"])})})}

case_subscription.set_subscriptions(
{'testStepExecutionEvents': case_subscription.CaseSubscriptions(subscriptions=subs)})
Expand All @@ -87,10 +87,10 @@ def test_ffkExecutionEvents(self):
c = controller.Controller(name="testStepFFKEventsController")
c.load_workflows_from_file(path=config.test_workflows_path + "basicWorkflowTest.workflow")

filter_sub = Subscription(events=['FilterSuccess', 'FilterError'])
flag_sub = Subscription(events=['FlagArgsValid', 'FlagArgsInvalid'], subscriptions={'length': filter_sub})
next_sub = Subscription(events=['NextStepTaken', 'NextStepNotTaken'], subscriptions={'regMatch': flag_sub})
step_sub = Subscription(events=["FunctionExecutionSuccess", "InputValidated", "ConditionalsExecuted"],
filter_sub = Subscription(events=['Filter Success', 'Filter Error'])
flag_sub = Subscription(events=['Flag Arguments Valid', 'Flag Arguments Invalid'], subscriptions={'length': filter_sub})
next_sub = Subscription(events=['Next Step Taken', 'Next Step Not Taken'], subscriptions={'regMatch': flag_sub})
step_sub = Subscription(events=["Function Execution Success", "Input Validated", "Conditionals Executed"],
subscriptions={'1': next_sub})
subs = {'testStepFFKEventsController':
Subscription(subscriptions=
Expand All @@ -116,28 +116,28 @@ def test_ffkExecutionEventsCase(self):
c = controller.Controller(name="testStepFFKEventsController")
c.load_workflows_from_file(path=config.test_workflows_path + "basicWorkflowTest.workflow")
workflow_name = construct_workflow_name_key('basicWorkflowTest', 'helloWorldWorkflow')
filter_sub = Subscription(events=['FilterError'])
flag_sub = Subscription(events=['FlagArgsValid',
'FlagArgsInvalid'], subscriptions={'length': filter_sub})
next_sub = Subscription(events=['NextStepTaken',
'NextStepNotTaken'],
filter_sub = Subscription(events=['Filter Error'])
flag_sub = Subscription(events=['Flag Arguments Valid',
'Flag Arguments Invalid'], subscriptions={'length': filter_sub})
next_sub = Subscription(events=['Next Step Taken',
'Next Step Not Taken'],
subscriptions={'regMatch': flag_sub})
step_sub = Subscription(events=['FunctionExecutionSuccess',
'InputValidated',
'ConditionalsExecuted'], subscriptions={'1': next_sub})
step_sub = Subscription(events=['Function Execution Success',
'Input Validated',
'Conditionals Executed'], subscriptions={'1': next_sub})
subs = {'testStepFFKEventsController':
Subscription(subscriptions=
{workflow_name:
Subscription(subscriptions=
{'start': step_sub})})}
global_subs = case_subscription.GlobalSubscriptions(step=['FunctionExecutionSuccess',
'InputValidated',
'ConditionalsExecuted'],
next_step=['NextStepTaken',
'NextStepNotTaken'],
flag=['FlagArgsValid',
'FlagArgsInvalid'],
filter=['FilterError'])
global_subs = case_subscription.GlobalSubscriptions(step=['Function Execution Success',
'Input Validated',
'Conditionals Executed'],
next_step=['Next Step Taken',
'Next Step Not Taken'],
flag=['Flag Arguments Valid',
'Flag Arguments Invalid'],
filter=['Filter Error'])
case_subscription.set_subscriptions(
{'testStepFFKEventsEvents': case_subscription.CaseSubscriptions(subscriptions=subs,
global_subscriptions=global_subs)})
Expand Down
23 changes: 21 additions & 2 deletions tests/test_workflow_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import core.case.subscription
import os
import core.config.paths
from gevent.event import Event
from core.case.callbacks import WorkflowShutdown


class TestWorkflowServer(ServerTestCase):
Expand Down Expand Up @@ -664,32 +666,49 @@ def test_execute_workflow_workflow_dne(self):
'error: invalid workflow name',
headers=self.headers)

def test_execute_worfklow(self):
def test_execute_workflow(self):
sync = Event()
workflow_name = helpers.construct_workflow_name_key('test', 'helloWorldWorkflow')
setup_subscriptions_for_step(workflow_name, ['start'])
start = datetime.utcnow()

def wait_for_completion(sender, **kwargs):
sync.set()

WorkflowShutdown.connect(wait_for_completion)

self.post_with_status_check('/playbook/test/helloWorldWorkflow/execute',
'success',
headers=self.headers)
sync.wait(timeout=10)
steps = executed_steps('defaultController', workflow_name, start, datetime.utcnow())
self.assertEqual(len(steps), 1)
step = steps[0]
ancestry = step['ancestry'].split(',')
self.assertEqual(ancestry[-1], "start")
self.assertEqual(step['data']['result'], "REPEATING: Hello World")

def test_execute_worfklow_in_memory(self):
def test_execute_workflow_in_memory(self):
sync = Event()
workflow_name = 'test_name'
data = {"playbook": 'basicWorkflow',
"template": 'helloWorldWorkflow'}

def wait_for_completion(sender, **kwargs):
sync.set()

WorkflowShutdown.connect(wait_for_completion)

self.post_with_status_check('/playbook/basicWorkflow/{0}/add'.format(workflow_name), 'success',
data=data, headers=self.headers)

workflow_name = helpers.construct_workflow_name_key('basicWorkflow', 'test_name')
setup_subscriptions_for_step(workflow_name, ['start'])
start = datetime.utcnow()
self.post_with_status_check('/playbook/basicWorkflow/test_name/execute',
'success',
headers=self.headers)
sync.wait(timeout=10)
steps = executed_steps('defaultController', workflow_name, start, datetime.utcnow())
self.assertEqual(len(steps), 1)
step = steps[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/util/case_db_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def setup_subscriptions_for_step(workflow_names, step_names, step_events=None, workflow_events=None):
step_events = step_events if step_events is not None else ['FunctionExecutionSuccess']
step_events = step_events if step_events is not None else ['Function Execution Success']
workflow_events = workflow_events if workflow_events is not None else []
step_sub = case_subscription.Subscription(events=step_events)
if isinstance(step_names, list):
Expand Down

0 comments on commit 596af45

Please sign in to comment.