Beispiel #1
0
class TestTimingSeriesEvents(TestCase):
    def setUp(self):
        self.timer = TimerMetricReporter('test')
        self.timer.update(10)
        self.timer.update(20)
        self.timer.update(20)
        self.timer.update(30)
        self.timer.update(40)

    def test_count(self):
        self.assertEqual(
            self.timer.count, 5,
            'Should record the count')

    def test_min(self):
        self.assertTrue(
            (math.fabs(self.timer.min() - 10.0) < 0.001),
            'Should calculate the minimum duration')

    def test_max(self):
        self.assertTrue(
            (math.fabs(self.timer.max() - 40.0) < 0.001),
            'Should calculate the maximum duration')

    def test_mean(self):
        self.assertTrue(
            (math.fabs(self.timer.mean() - 24.0) < 0.001),
            'Should calculate the mean duration')

    def test_std_dev(self):
        self.assertTrue(
            (math.fabs(self.timer.std_dev() - 11.401) < 0.001),
            'Should calculate the standard deviation')

    def test_percentiles(self):
        percentiles = self.timer.percentiles(0.5, 0.95, 0.98, 0.99, 0.999)
        self.assertTrue(
            (math.fabs(percentiles[0] - 20.0) < 0.001),
            'Should calculate the median')
        self.assertTrue(
            (math.fabs(percentiles[1] - 40.0) < 0.001),
            'Should calculate the p95')
        self.assertTrue(
            (math.fabs(percentiles[2] - 40.0) < 0.001),
            'Should calculate the p98')
        self.assertTrue(
            (math.fabs(percentiles[3] - 40.0) < 0.001),
            'Should calculate the p99')
        self.assertTrue(
            (math.fabs(percentiles[4] - 40.0) < 0.001),
            'Should calculate the p999')

    def test_values(self):
        self.assertEqual(
            set(self.timer.get_values()), set([10, 20, 20, 30, 40]),
            'Should have a series of values')
class TestTimingSeriesEvents(TestCase):
    def setUp(self):
        self.timer = TimerMetricReporter('test')
        self.timer.update(10)
        self.timer.update(20)
        self.timer.update(20)
        self.timer.update(30)
        self.timer.update(40)

    def test_count(self):
        self.assertEqual(self.timer.count, 5, 'Should record the count')

    def test_min(self):
        self.assertTrue((math.fabs(self.timer.min() - 10.0) < 0.001),
                        'Should calculate the minimum duration')

    def test_max(self):
        self.assertTrue((math.fabs(self.timer.max() - 40.0) < 0.001),
                        'Should calculate the maximum duration')

    def test_mean(self):
        self.assertTrue((math.fabs(self.timer.mean() - 24.0) < 0.001),
                        'Should calculate the mean duration')

    def test_std_dev(self):
        self.assertTrue((math.fabs(self.timer.std_dev() - 11.401) < 0.001),
                        'Should calculate the standard deviation')

    def test_percentiles(self):
        percentiles = self.timer.percentiles(0.5, 0.95, 0.98, 0.99, 0.999)
        self.assertTrue((math.fabs(percentiles[0] - 20.0) < 0.001),
                        'Should calculate the median')
        self.assertTrue((math.fabs(percentiles[1] - 40.0) < 0.001),
                        'Should calculate the p95')
        self.assertTrue((math.fabs(percentiles[2] - 40.0) < 0.001),
                        'Should calculate the p98')
        self.assertTrue((math.fabs(percentiles[3] - 40.0) < 0.001),
                        'Should calculate the p99')
        self.assertTrue((math.fabs(percentiles[4] - 40.0) < 0.001),
                        'Should calculate the p999')

    def test_values(self):
        self.assertEqual(set(self.timer.get_values()),
                         set([10, 20, 20, 30,
                              40]), 'Should have a series of values')