diff --git a/opentelemetry-sdk/tests/metrics/test_aggregation.py b/opentelemetry-sdk/tests/metrics/test_aggregation.py index ceb69f243f5..536584df4d6 100644 --- a/opentelemetry-sdk/tests/metrics/test_aggregation.py +++ b/opentelemetry-sdk/tests/metrics/test_aggregation.py @@ -28,7 +28,7 @@ class TestSynchronousSumAggregation(TestCase): - def test_aggregate(self): + def test_aggregate_delta(self): """ `SynchronousSumAggregation` aggregates data for sum metric points """ @@ -53,7 +53,32 @@ def test_aggregate(self): self.assertEqual(synchronous_sum_aggregation._value, 2) - def test_collect(self): + def test_aggregate_cumulative(self): + """ + `SynchronousSumAggregation` aggregates data for sum metric points + """ + + synchronous_sum_aggregation = SumAggregation( + True, AggregationTemporality.CUMULATIVE + ) + + synchronous_sum_aggregation.aggregate(Measurement(1)) + synchronous_sum_aggregation.aggregate(Measurement(2)) + synchronous_sum_aggregation.aggregate(Measurement(3)) + + self.assertEqual(synchronous_sum_aggregation._value, 6) + + synchronous_sum_aggregation = SumAggregation( + True, AggregationTemporality.CUMULATIVE + ) + + synchronous_sum_aggregation.aggregate(Measurement(1)) + synchronous_sum_aggregation.aggregate(Measurement(-2)) + synchronous_sum_aggregation.aggregate(Measurement(3)) + + self.assertEqual(synchronous_sum_aggregation._value, 2) + + def test_collect_delta(self): """ `SynchronousSumAggregation` collects sum metric points """ @@ -78,6 +103,31 @@ def test_collect(self): second_sum.start_time_unix_nano, first_sum.start_time_unix_nano ) + def test_collect_cumulative(self): + """ + `SynchronousSumAggregation` collects sum metric points + """ + + synchronous_sum_aggregation = SumAggregation( + True, AggregationTemporality.CUMULATIVE + ) + + synchronous_sum_aggregation.aggregate(Measurement(1)) + first_sum = synchronous_sum_aggregation.collect() + + self.assertEqual(first_sum.value, 1) + self.assertTrue(first_sum.is_monotonic) + + synchronous_sum_aggregation.aggregate(Measurement(1)) + second_sum = synchronous_sum_aggregation.collect() + + self.assertEqual(second_sum.value, 2) + self.assertTrue(second_sum.is_monotonic) + + self.assertEqual( + second_sum.start_time_unix_nano, first_sum.start_time_unix_nano + ) + class TestLastValueAggregation(TestCase): def test_aggregate(self):