Пример #1
0
    def testBenchFindChangePoints_UniqueBenchRunsOnce(self):
        test = self._AddTestData('test', _SAMPLE_SERIES, anomaly.DOWN)
        self._AddAnomalyForTest(4, 123, test.key)

        bench_find_anomalies.SetupBaseDataForBench()

        self.ExecuteDeferredTasks(bench_find_anomalies._TASK_QUEUE_NAME)

        bench_name = 'a_bench_name1'
        bench_description = 'Test find_change_points v1'
        bench_find_anomalies._EXPERIMENTAL_FUNCTIONS = {
            bench_name: find_change_points_exp.RunFindChangePoints
        }

        bench_find_anomalies.BenchFindChangePoints(bench_name,
                                                   bench_description)

        # A task should be added.
        task_queue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        tasks = task_queue.GetTasks(bench_find_anomalies._TASK_QUEUE_NAME)
        self.assertEqual(1, len(tasks))

        with self.assertRaises(ValueError):
            bench_find_anomalies.BenchFindChangePoints(bench_name,
                                                       bench_description)
Пример #2
0
    def testBenchFindChangePoints_Basic(self, add_report_to_log_mock):
        test = self._AddTestData('test', _SAMPLE_SERIES, anomaly.DOWN)

        # Add untriaged anomalies.
        self._AddAnomalyForTest(7, None, test.key)

        # Add confirmed anomalies.
        self._AddAnomalyForTest(4, 123, test.key)

        # Add invalid anomalies.
        self._AddAnomalyForTest(10, -1, test.key)

        bench_find_anomalies.SetupBaseDataForBench()

        self.ExecuteDeferredTasks(bench_find_anomalies._TASK_QUEUE_NAME)

        test_benches = bench_find_anomalies.TestBench.query().fetch()
        self.assertEqual(1, len(test_benches))

        self.assertEqual(_SAMPLE_SERIES, test_benches[0].data_series)
        self.assertEqual([[1, 2, 3, 4, 5, 6, 7, 8]],
                         test_benches[0].base_anomaly_revs)
        self.assertEqual([[6, 7, 8, 9, 10, 11, 12]],
                         test_benches[0].invalid_anomaly_revs)
        self.assertEqual([[1, 2, 3, 4, 5, 6, 7, 8]],
                         test_benches[0].confirmed_anomaly_revs)

        bench_name = 'find_change_points_default'
        bench_description = 'A description.'
        bench_find_anomalies.BenchFindChangePoints(bench_name,
                                                   bench_description)

        # Layered cache set.
        bench_key = '%s.%s' % (bench_name, bench_description)
        self.assertEqual(
            {bench_key: True},
            layered_cache.Get(
                bench_find_anomalies._FIND_ANOMALIES_BENCH_CACHE_KEY))

        task_queue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        test_support.execute_until_empty(task_queue,
                                         bench_find_anomalies._TASK_QUEUE_NAME)

        expected_result_dict = {
            'bench_name': bench_name,
            'description': bench_description,
            'invalid_alerts': '0/1',
            'confirmed_alerts': '1/1',
            'new_alerts': 0,
            'total_alerts': '1/1',
            'unconfirmed_alert_links': '',
            'extra_alert_links': '',
        }
        add_report_to_log_mock.assert_called_once_with(expected_result_dict)