Skip to content

Commit

Permalink
Add cumulative test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Feb 1, 2022
1 parent 6e64e87 commit 5f8df2a
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions opentelemetry-sdk/tests/metrics/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


class TestSynchronousSumAggregation(TestCase):
def test_aggregate(self):
def test_aggregate_delta(self):
"""
`SynchronousSumAggregation` aggregates data for sum metric points
"""
Expand All @@ -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
"""
Expand All @@ -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):
Expand Down

0 comments on commit 5f8df2a

Please sign in to comment.