From 5110a7d0aea69e65755c092a11140f9348d02d0f Mon Sep 17 00:00:00 2001 From: Ashley Hedberg Date: Wed, 22 May 2019 16:12:28 -0400 Subject: [PATCH 1/2] Add test coverage for find* methods in IsolatedStoreImpl Signed-off-by: Ashley Hedberg --- test/common/stats/isolated_store_impl_test.cc | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/common/stats/isolated_store_impl_test.cc b/test/common/stats/isolated_store_impl_test.cc index 7e9f1a33169a1..65d43a29355e0 100644 --- a/test/common/stats/isolated_store_impl_test.cc +++ b/test/common/stats/isolated_store_impl_test.cc @@ -36,6 +36,15 @@ TEST_F(StatsIsolatedStoreImplTest, All) { EXPECT_EQ(0, c1.tags().size()); EXPECT_EQ(0, c1.tags().size()); + StatNameManagedStorage c1_name("c1", store_.symbolTable()); + c1.add(100); + auto found_counter = store_.findCounter(c1_name.statName()); + ASSERT_TRUE(found_counter.has_value()); + EXPECT_EQ(&c1, &found_counter->get()); + EXPECT_EQ(100, found_counter->get().value()); + c1.add(100); + EXPECT_EQ(200, found_counter->get().value()); + Gauge& g1 = store_.gauge("g1"); Gauge& g2 = scope1->gauge("g2"); EXPECT_EQ("g1", g1.name()); @@ -45,6 +54,15 @@ TEST_F(StatsIsolatedStoreImplTest, All) { EXPECT_EQ(0, g1.tags().size()); EXPECT_EQ(0, g2.tags().size()); + StatNameManagedStorage g1_name("g1", store_.symbolTable()); + g1.set(100); + auto found_gauge = store_.findGauge(g1_name.statName()); + ASSERT_TRUE(found_gauge.has_value()); + EXPECT_EQ(&g1, &found_gauge->get()); + EXPECT_EQ(100, found_gauge->get().value()); + g1.set(0); + EXPECT_EQ(0, found_gauge->get().value()); + Histogram& h1 = store_.histogram("h1"); Histogram& h2 = scope1->histogram("h2"); scope1->deliverHistogramToSinks(h2, 0); @@ -57,6 +75,11 @@ TEST_F(StatsIsolatedStoreImplTest, All) { h1.recordValue(200); h2.recordValue(200); + StatNameManagedStorage h1_name("h1", store_.symbolTable()); + auto found_histogram = store_.findHistogram(h1_name.statName()); + ASSERT_TRUE(found_histogram.has_value()); + EXPECT_EQ(&h1, &found_histogram->get()); + ScopePtr scope2 = scope1->createScope("foo."); EXPECT_EQ("scope1.foo.bar", scope2->counter("bar").name()); From 436154d5736fd197eea3218137620b885378f2a1 Mon Sep 17 00:00:00 2001 From: Ashley Hedberg Date: Thu, 23 May 2019 09:52:52 -0400 Subject: [PATCH 2/2] add coverage for nullopt cases Signed-off-by: Ashley Hedberg --- test/common/stats/isolated_store_impl_test.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/common/stats/isolated_store_impl_test.cc b/test/common/stats/isolated_store_impl_test.cc index 65d43a29355e0..62b113e2fc11f 100644 --- a/test/common/stats/isolated_store_impl_test.cc +++ b/test/common/stats/isolated_store_impl_test.cc @@ -89,6 +89,11 @@ TEST_F(StatsIsolatedStoreImplTest, All) { EXPECT_EQ(4UL, store_.counters().size()); EXPECT_EQ(2UL, store_.gauges().size()); + + StatNameManagedStorage nonexistent_name("nonexistent", store_.symbolTable()); + EXPECT_EQ(store_.findCounter(nonexistent_name.statName()), absl::nullopt); + EXPECT_EQ(store_.findGauge(nonexistent_name.statName()), absl::nullopt); + EXPECT_EQ(store_.findHistogram(nonexistent_name.statName()), absl::nullopt); } TEST_F(StatsIsolatedStoreImplTest, AllWithSymbolTable) {