Skip to content

Commit

Permalink
add tests..
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Sep 29, 2023
1 parent 06cd640 commit 9e34355
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions sdk/test/metrics/sync_instruments_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,43 @@ TEST(SyncInstruments, DoubleHistogram)
histogram.Record(10.10, opentelemetry::common::KeyValueIterableView<M>({}),
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<SyncWritableMetricStorage> 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<double>::quiet_NaN(),
opentelemetry::context::Context{}); // This is ignored too
gauge.Record(std::numeric_limits<double>::infinity(),
opentelemetry::context::Context{}); // This is ignored too

gauge.Record(10.10,
opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}),
opentelemetry::context::Context{});
gauge.Record(10.10, opentelemetry::common::KeyValueIterableView<M>({}),
opentelemetry::context::Context{});
}

TEST(SyncInstruments, LongGauge)
{
InstrumentDescriptor instrument_descriptor = {"double_gauge", "description", "1",
InstrumentType::kGauge, InstrumentValueType::kLong};
std::unique_ptr<SyncWritableMetricStorage> metric_storage(new SyncMultiMetricStorage());
DoubleGauge gauge(instrument_descriptor, std::move(metric_storage));
gauge.Record(10, opentelemetry::context::Context{});
gauge.Record(std::numeric_limits<uint64_t>::quiet_NaN(),
opentelemetry::context::Context{}); // This is ignored too
gauge.Record(std::numeric_limits<uint64_t>::infinity(),
opentelemetry::context::Context{}); // This is ignored too

gauge.Record(10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}),
opentelemetry::context::Context{});
gauge.Record(10, opentelemetry::common::KeyValueIterableView<M>({}),
opentelemetry::context::Context{});
}
#endif

0 comments on commit 9e34355

Please sign in to comment.