Ejemplo n.º 1
0
    def test_convert_workflow_time_average(self):
        expected_json = {'workflows': [{'count': 100,
                                        'avg_time': '1 day, 0:01:40.000500',
                                        'name': 'workflow4'},
                                       {'count': 2,
                                        'avg_time': '0:00:00.001000',
                                        'name': 'workflow2'},
                                       {'count': 0,
                                        'avg_time': '0:01:40.000001',
                                        'name': 'workflow3'},
                                       {'count': 0,
                                        'avg_time': '100 days, 0:00:00.000001',
                                        'name': 'workflow1'}]}

        wf1 = WorkflowMetric(uuid.uuid4(), 'workflow1', timedelta(100, 0, 1).total_seconds())
        wf1.count = 0
        wf2 = WorkflowMetric(uuid.uuid4(), 'workflow2', timedelta(0, 0, 1000).total_seconds())
        wf2.count = 2
        wf3 = WorkflowMetric(uuid.uuid4(), 'workflow3', timedelta(0, 100, 1).total_seconds())
        wf3.count = 0
        wf4 = WorkflowMetric(uuid.uuid4(), 'workflow4', timedelta(1, 100, 500).total_seconds())
        wf4.count = 100

        current_app.running_context.execution_db.session.add_all([wf1, wf2, wf3, wf4])
        current_app.running_context.execution_db.session.commit()

        converted = _convert_workflow_time_averages()
        orderless_list_compare(self, converted.keys(), ['workflows'])
        self.assertEqual(len(converted['workflows']), len(expected_json['workflows']))
        for workflow in expected_json['workflows']:
            self.assertIn(workflow, converted['workflows'])
Ejemplo n.º 2
0
    def test_convert_workflow_time_average(self):
        expected_json = {'workflows': [{'count': 100,
                                        'avg_time': '1 day, 0:01:40.000500',
                                        'name': 'workflow4'},
                                       {'count': 2,
                                        'avg_time': '0:00:00.001000',
                                        'name': 'workflow2'},
                                       {'count': 0,
                                        'avg_time': '0:01:40.000001',
                                        'name': 'workflow3'},
                                       {'count': 0,
                                        'avg_time': '100 days, 0:00:00.000001',
                                        'name': 'workflow1'}]}

        wf1 = WorkflowMetric(uuid.uuid4(), 'workflow1', timedelta(100, 0, 1).total_seconds())
        wf1.count = 0
        wf2 = WorkflowMetric(uuid.uuid4(), 'workflow2', timedelta(0, 0, 1000).total_seconds())
        wf2.count = 2
        wf3 = WorkflowMetric(uuid.uuid4(), 'workflow3', timedelta(0, 100, 1).total_seconds())
        wf3.count = 0
        wf4 = WorkflowMetric(uuid.uuid4(), 'workflow4', timedelta(1, 100, 500).total_seconds())
        wf4.count = 100

        current_app.running_context.execution_db.session.add_all([wf1, wf2, wf3, wf4])
        current_app.running_context.execution_db.session.commit()

        converted = _convert_workflow_time_averages()
        orderless_list_compare(self, converted.keys(), ['workflows'])
        self.assertEqual(len(converted['workflows']), len(expected_json['workflows']))
        for workflow in expected_json['workflows']:
            self.assertIn(workflow, converted['workflows'])
Ejemplo n.º 3
0
    def test_workflow_metrics(self):
        error_id = execution_db_help.load_workflow('multiactionError', 'multiactionErrorWorkflow').id
        test_id = execution_db_help.load_workflow('multiactionWorkflowTest', 'multiactionWorkflow').id

        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)

        response = self.test_client.get('/api/metrics/workflows', headers=self.headers)
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.get_data(as_text=True))
        self.assertDictEqual(response, _convert_workflow_time_averages())
Ejemplo n.º 4
0
    def test_workflow_metrics(self):
        error_id = execution_db_help.load_workflow('multiactionError', 'multiactionErrorWorkflow').id
        test_id = execution_db_help.load_workflow('multiactionWorkflowTest', 'multiactionWorkflow').id

        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)

        response = self.test_client.get('/api/metrics/workflows', headers=self.headers)
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.get_data(as_text=True))
        self.assertDictEqual(response, _convert_workflow_time_averages())
Ejemplo n.º 5
0
 def test_convert_workflow_time_average(self):
     test1 = {
         'workflow1': {
             'count': 0,
             'avg_time': timedelta(100, 0, 1)
         },
         'workflow2': {
             'count': 2,
             'avg_time': timedelta(0, 0, 1000)
         },
         'workflow3': {
             'count': 0,
             'avg_time': timedelta(0, 100, 1)
         },
         'workflow4': {
             'count': 100,
             'avg_time': timedelta(1, 100, 500)
         }
     }
     expected_json = {
         'workflows': [{
             'count': 100,
             'avg_time': '1 day, 0:01:40.000500',
             'name': 'workflow4'
         }, {
             'count': 2,
             'avg_time': '0:00:00.001000',
             'name': 'workflow2'
         }, {
             'count': 0,
             'avg_time': '0:01:40.000001',
             'name': 'workflow3'
         }, {
             'count': 0,
             'avg_time': '100 days, 0:00:00.000001',
             'name': 'workflow1'
         }]
     }
     metrics.workflow_metrics = test1
     converted = _convert_workflow_time_averages()
     orderless_list_compare(self, converted.keys(), ['workflows'])
     self.assertEqual(len(converted['workflows']),
                      len(expected_json['workflows']))
     for workflow in expected_json['workflows']:
         self.assertIn(workflow, converted['workflows'])
Ejemplo n.º 6
0
    def test_workflow_metrics(self):
        server.running_context.controller.load_playbook(
            resource=config.test_workflows_path + 'multiactionError.playbook')
        server.running_context.controller.load_playbook(
            resource=config.test_workflows_path +
            'multiactionWorkflowTest.playbook')
        server.running_context.controller.execute_workflow(
            'multiactionError', 'multiactionErrorWorkflow')
        server.running_context.controller.execute_workflow(
            'multiactionError', 'multiactionErrorWorkflow')
        server.running_context.controller.execute_workflow(
            'multiactionWorkflowTest', 'multiactionWorkflow')
        server.running_context.controller.wait_and_reset(3)

        response = self.app.get('/metrics/workflows', headers=self.headers)
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.get_data(as_text=True))
        self.assertDictEqual(response, _convert_workflow_time_averages())