From e0bdcccb806be01ee8c07d8b94cfb7be0acc7bf1 Mon Sep 17 00:00:00 2001 From: Lalit Date: Fri, 29 Sep 2023 16:56:00 -0700 Subject: [PATCH] fix test --- .../opentelemetry/metrics/sync_instruments.h | 2 +- sdk/test/metrics/sync_instruments_test.cc | 52 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index 4950c2c13d..43a5d69fc6 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -288,7 +288,7 @@ class Gauge : public SynchronousInstrument * * @param value The increment amount. MUST be non-negative. */ - virtual void Record(T value) noexcept { this->Record(value, nullptr, nullptr); } + void Record(T value) noexcept { this->Record(value, nullptr, nullptr); } /** * Record a value diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index 2234fca1a8..d4cabbd37e 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -140,25 +140,25 @@ TEST(SyncInstruments, DoubleHistogram) opentelemetry::context::Context{}); } -#if OPEN_TELEMETRY_ABI_VERSION_NO >= 2 +#if OPENTELEMETRY_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{}); + auto gauge = std::unique_ptr>( + new DoubleGauge(instrument_descriptor, std::move(metric_storage))); + EXPECT_NO_THROW(gauge->Record(10.10, opentelemetry::context::Context{})); + EXPECT_NO_THROW(gauge->Record(-10.10, opentelemetry::context::Context{})); // This is ignored. + EXPECT_NO_THROW(gauge->Record(std::numeric_limits::quiet_NaN(), + opentelemetry::context::Context{})); // This is ignored too + EXPECT_NO_THROW(gauge->Record(std::numeric_limits::infinity(), + opentelemetry::context::Context{})); // This is ignored too + EXPECT_NO_THROW(gauge->Record( + 10.10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(gauge->Record(10.10, opentelemetry::common::KeyValueIterableView({}), + opentelemetry::context::Context{})); } TEST(SyncInstruments, LongGauge) @@ -166,16 +166,18 @@ 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{}); + auto gauge = std::unique_ptr>( + new LongGauge(instrument_descriptor, std::move(metric_storage))); + EXPECT_NO_THROW(gauge->Record(10, opentelemetry::context::Context{})); + EXPECT_NO_THROW(gauge->Record(std::numeric_limits::quiet_NaN(), + opentelemetry::context::Context{})); // This is ignored too + EXPECT_NO_THROW(gauge->Record(std::numeric_limits::infinity(), + opentelemetry::context::Context{})); // This is ignored too + + EXPECT_NO_THROW(gauge->Record( + 10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(gauge->Record(10, opentelemetry::common::KeyValueIterableView({}), + opentelemetry::context::Context{})); } #endif \ No newline at end of file