Skip to content

Commit

Permalink
Add test case that shows how get_metrics_data can return None
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Sep 16, 2024
1 parent d5fb2c4 commit 3027da2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,32 @@
NumberDataPoint,
Sum,
)
from opentelemetry.sdk.metrics.view import SumAggregation


class TestInMemoryMetricReader(TestCase):

def test_get_metrics_data_returns_none(self):

aggregation = SumAggregation()

reader = InMemoryMetricReader(
preferred_aggregation={Counter: aggregation},
preferred_temporality={Counter: AggregationTemporality.DELTA},
)

provider = MeterProvider(metric_readers=[reader])
meter = provider.get_meter("name", "version")

counter = meter.create_counter("counter")

self.assertIsNone(reader.get_metrics_data())

counter.add(1)

self.assertIsNotNone(reader.get_metrics_data())
self.assertIsNone(reader.get_metrics_data())

def test_no_metrics(self):
mock_collect_callback = Mock(return_value=[])
reader = InMemoryMetricReader()
Expand Down

0 comments on commit 3027da2

Please sign in to comment.