From 9e34355e518c018e3e92f11394b5f76620ea6ef9 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 28 Sep 2023 23:55:29 -0700 Subject: [PATCH] add tests.. --- sdk/test/metrics/sync_instruments_test.cc | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index 5442dcc395..2234fca1a8 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -139,3 +139,43 @@ TEST(SyncInstruments, DoubleHistogram) histogram.Record(10.10, opentelemetry::common::KeyValueIterableView({}), opentelemetry::context::Context{}); } + +#if OPEN_TELEMETRY_ABI_VERSION_NO >= 2 +TEST(SyncInstruments, DoubleGauge) +{ + InstrumentDescriptor instrument_descriptor = { + "double_gauge", "description", "1", InstrumentType::kGauge, InstrumentValueType::kDouble}; + std::unique_ptr metric_storage(new SyncMultiMetricStorage()); + DoubleGauge gauge(instrument_descriptor, std::move(metric_storage)); + gauge.Record(10.10, opentelemetry::context::Context{}); + gauge.Record(-10.10, opentelemetry::context::Context{}); // This is ignored. + gauge.Record(std::numeric_limits::quiet_NaN(), + opentelemetry::context::Context{}); // This is ignored too + gauge.Record(std::numeric_limits::infinity(), + opentelemetry::context::Context{}); // This is ignored too + + gauge.Record(10.10, + opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{}); + gauge.Record(10.10, opentelemetry::common::KeyValueIterableView({}), + opentelemetry::context::Context{}); +} + +TEST(SyncInstruments, LongGauge) +{ + InstrumentDescriptor instrument_descriptor = {"double_gauge", "description", "1", + InstrumentType::kGauge, InstrumentValueType::kLong}; + std::unique_ptr metric_storage(new SyncMultiMetricStorage()); + DoubleGauge gauge(instrument_descriptor, std::move(metric_storage)); + gauge.Record(10, opentelemetry::context::Context{}); + gauge.Record(std::numeric_limits::quiet_NaN(), + opentelemetry::context::Context{}); // This is ignored too + gauge.Record(std::numeric_limits::infinity(), + opentelemetry::context::Context{}); // This is ignored too + + gauge.Record(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{}); + gauge.Record(10, opentelemetry::common::KeyValueIterableView({}), + opentelemetry::context::Context{}); +} +#endif \ No newline at end of file