Skip to content

Commit a31411e

Browse files
committed
Add delta test case
1 parent f65efbc commit a31411e

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponential_bucket_histogram_aggregation.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ def test_collect_results_cumulative(self):
925925
self.assertEqual(collection_1.min, 0.045)
926926
self.assertEqual(collection_1.max, 8)
927927

928-
def test_merge_collect(self):
928+
def test_merge_collect_cumulative(self):
929929
exponential_histogram_aggregation = (
930930
_ExponentialBucketHistogramAggregation(Mock(), Mock(), max_size=4)
931931
)
@@ -965,3 +965,44 @@ def test_merge_collect(self):
965965
)
966966

967967
self.assertEqual(result.scale, result_1.scale)
968+
969+
def test_merge_collect_delta(self):
970+
exponential_histogram_aggregation = (
971+
_ExponentialBucketHistogramAggregation(Mock(), Mock(), max_size=4)
972+
)
973+
974+
for value in [2, 4, 8, 16]:
975+
exponential_histogram_aggregation.aggregate(
976+
Measurement(value, Mock())
977+
)
978+
979+
self.assertEqual(exponential_histogram_aggregation._mapping.scale, 0)
980+
self.assertEqual(exponential_histogram_aggregation._positive.offset, 0)
981+
self.assertEqual(
982+
exponential_histogram_aggregation._positive.counts, [1, 1, 1, 1]
983+
)
984+
985+
result = exponential_histogram_aggregation.collect(
986+
AggregationTemporality.DELTA,
987+
0,
988+
)
989+
990+
for value in [1, 2, 4, 8]:
991+
exponential_histogram_aggregation.aggregate(
992+
Measurement(1 / value, Mock())
993+
)
994+
995+
self.assertEqual(exponential_histogram_aggregation._mapping.scale, 0)
996+
self.assertEqual(
997+
exponential_histogram_aggregation._positive.offset, -4
998+
)
999+
self.assertEqual(
1000+
exponential_histogram_aggregation._positive.counts, [1, 1, 1, 1]
1001+
)
1002+
1003+
result_1 = exponential_histogram_aggregation.collect(
1004+
AggregationTemporality.DELTA,
1005+
0,
1006+
)
1007+
1008+
self.assertEqual(result.scale, result_1.scale)

0 commit comments

Comments
 (0)