def test_workflow_metrics(self): execution_db_help.load_playbooks( ['multiactionError', 'multiactionWorkflowTest']) error_id = current_app.running_context.execution_db.session.query( Workflow).join(Workflow.playbook).filter( and_(Workflow.name == 'multiactionErrorWorkflow', Playbook.name == 'multiactionError')).first().id test_id = current_app.running_context.execution_db.session.query( Workflow).join(Workflow.playbook).filter( and_(Workflow.name == 'multiactionWorkflow', Playbook.name == 'multiactionWorkflowTest')).first().id error_key = 'multiactionErrorWorkflow' multiaction_key = 'multiactionWorkflow' current_app.running_context.executor.execute_workflow(error_id) current_app.running_context.executor.execute_workflow(error_id) current_app.running_context.executor.execute_workflow(test_id) current_app.running_context.executor.wait_and_reset(3) keys = [error_key, multiaction_key] workflow_metrics = current_app.running_context.execution_db.session.query( WorkflowMetric).all() self.assertEqual(len(workflow_metrics), len(keys)) for workflow in workflow_metrics: self.assertIn(workflow.workflow_name, keys) self.assertIsNotNone(workflow.avg_time) self.assertIsNotNone(workflow.count) self.assertGreater(workflow.avg_time, 0) if workflow.workflow_name == error_key: self.assertEqual(workflow.count, 2) elif workflow.workflow_name == multiaction_key: self.assertEqual(workflow.count, 1)
def test_workflow_metrics(self): execution_db_help.load_playbooks( ['multiactionError', 'multiactionWorkflowTest']) error_id = executiondb.execution_db.session.query(Workflow).join( Workflow.playbook).filter( and_(Workflow.name == 'multiactionErrorWorkflow', Playbook.name == 'multiactionError')).first().id test_id = executiondb.execution_db.session.query(Workflow).join( Workflow.playbook).filter( and_(Workflow.name == 'multiactionWorkflow', Playbook.name == 'multiactionWorkflowTest')).first().id error_key = 'multiactionErrorWorkflow' multiaction_key = 'multiactionWorkflow' server.running_context.executor.execute_workflow(error_id) server.running_context.executor.execute_workflow(error_id) server.running_context.executor.execute_workflow(test_id) server.running_context.executor.wait_and_reset(3) keys = [error_key, multiaction_key] orderless_list_compare(self, list(metrics.workflow_metrics.keys()), keys) for key in keys: orderless_list_compare(self, metrics.workflow_metrics[key], ['count', 'avg_time']) self.assertEqual(metrics.workflow_metrics[error_key]['count'], 2) self.assertEqual(metrics.workflow_metrics[multiaction_key]['count'], 1)
def test_workflow_metrics(self): execution_db_help.load_playbooks(['multiactionError', 'multiactionWorkflowTest']) error_id = current_app.running_context.execution_db.session.query(Workflow).join(Workflow.playbook).filter(and_( Workflow.name == 'multiactionErrorWorkflow', Playbook.name == 'multiactionError')).first().id test_id = current_app.running_context.execution_db.session.query(Workflow).join(Workflow.playbook).filter(and_( Workflow.name == 'multiactionWorkflow', Playbook.name == 'multiactionWorkflowTest')).first().id error_key = 'multiactionErrorWorkflow' multiaction_key = 'multiactionWorkflow' current_app.running_context.executor.execute_workflow(error_id) current_app.running_context.executor.execute_workflow(error_id) current_app.running_context.executor.execute_workflow(test_id) current_app.running_context.executor.wait_and_reset(3) keys = [error_key, multiaction_key] workflow_metrics = current_app.running_context.execution_db.session.query(WorkflowMetric).all() self.assertEqual(len(workflow_metrics), len(keys)) for workflow in workflow_metrics: self.assertIn(workflow.workflow_name, keys) self.assertIsNotNone(workflow.avg_time) self.assertIsNotNone(workflow.count) self.assertGreater(workflow.avg_time, 0) if workflow.workflow_name == error_key: self.assertEqual(workflow.count, 2) elif workflow.workflow_name == multiaction_key: self.assertEqual(workflow.count, 1)
def test_read_all_playbooks(self): playbook_names = ['basicWorkflowTest', 'dataflowTest'] execution_db_help.load_playbooks(playbook_names) response = self.get_with_status_check('/api/playbooks', headers=self.headers) for playbook in response: for workflow in playbook['workflows']: workflow.pop('id') self.assertEqual(len(response), len(playbook_names)) for playbook in response: self.assertIn(playbook['name'], playbook_names)