Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions test/common/stats/thread_local_store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ TEST_F(StatsThreadLocalStoreTest, NoTls) {
store_->deliverHistogramToSinks(h1, 100);

EXPECT_EQ(2UL, store_->counters().size());
EXPECT_EQ(&c1, store_->counters().front().get());
EXPECT_EQ(2L, store_->counters().front().use_count());
EXPECT_EQ(&c1, TestUtility::findCounter(*store_, "c1").get());
EXPECT_EQ(2L, TestUtility::findCounter(*store_, "c1").use_count());
EXPECT_EQ(1UL, store_->gauges().size());
EXPECT_EQ(&g1, store_->gauges().front().get());
EXPECT_EQ(&g1, store_->gauges().front().get()); // front() ok when size()==1
EXPECT_EQ(2L, store_->gauges().front().use_count());

// Includes overflow stat.
Expand All @@ -212,20 +212,20 @@ TEST_F(StatsThreadLocalStoreTest, Tls) {
EXPECT_EQ(&h1, &store_->histogram("h1"));

EXPECT_EQ(2UL, store_->counters().size());
EXPECT_EQ(&c1, store_->counters().front().get());
EXPECT_EQ(3L, store_->counters().front().use_count());
EXPECT_EQ(&c1, TestUtility::findCounter(*store_, "c1").get());
EXPECT_EQ(3L, TestUtility::findCounter(*store_, "c1").use_count());
EXPECT_EQ(1UL, store_->gauges().size());
EXPECT_EQ(&g1, store_->gauges().front().get());
EXPECT_EQ(&g1, store_->gauges().front().get()); // front() ok when size()==1
EXPECT_EQ(3L, store_->gauges().front().use_count());

store_->shutdownThreading();
tls_.shutdownThread();

EXPECT_EQ(2UL, store_->counters().size());
EXPECT_EQ(&c1, store_->counters().front().get());
EXPECT_EQ(2L, store_->counters().front().use_count());
EXPECT_EQ(&c1, TestUtility::findCounter(*store_, "c1").get());
EXPECT_EQ(2L, TestUtility::findCounter(*store_, "c1").use_count());
EXPECT_EQ(1UL, store_->gauges().size());
EXPECT_EQ(&g1, store_->gauges().front().get());
EXPECT_EQ(&g1, store_->gauges().front().get()); // front() ok when size()==1
EXPECT_EQ(2L, store_->gauges().front().use_count());

// Includes overflow stat.
Expand Down Expand Up @@ -291,9 +291,9 @@ TEST_F(StatsThreadLocalStoreTest, ScopeDelete) {
EXPECT_CALL(*alloc_, alloc(_));
scope1->counter("c1");
EXPECT_EQ(2UL, store_->counters().size());
CounterSharedPtr c1 = store_->counters().front();
CounterSharedPtr c1 = TestUtility::findCounter(*store_, "scope1.c1");
EXPECT_EQ("scope1.c1", c1->name());
EXPECT_EQ(store_->source().cachedCounters().front(), c1);
EXPECT_EQ(TestUtility::findByName(store_->source().cachedCounters(), "scope1.c1"), c1);

EXPECT_CALL(main_thread_dispatcher_, post(_));
EXPECT_CALL(tls_, runOnAllThreads(_));
Expand Down
14 changes: 2 additions & 12 deletions test/test_common/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,11 @@ void TestUtility::feedBufferWithRandomCharacters(Buffer::Instance& buffer, uint6
}

Stats::CounterSharedPtr TestUtility::findCounter(Stats::Store& store, const std::string& name) {
for (auto counter : store.counters()) {
if (counter->name() == name) {
return counter;
}
}
return nullptr;
return findByName(store.counters(), name);
}

Stats::GaugeSharedPtr TestUtility::findGauge(Stats::Store& store, const std::string& name) {
for (auto gauge : store.gauges()) {
if (gauge->name() == name) {
return gauge;
}
}
return nullptr;
return findByName(store.gauges(), name);
}

std::list<Network::Address::InstanceConstSharedPtr>
Expand Down
15 changes: 15 additions & 0 deletions test/test_common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ class TestUtility {
static void feedBufferWithRandomCharacters(Buffer::Instance& buffer, uint64_t n_char,
uint64_t seed = 0);

/**
* Finds a stat in a vector with the given name.
* @param name the stat name to look for.
* @param v the vector of stats.
* @return the stat
*/
template <typename T> static T findByName(const std::vector<T>& v, const std::string& name) {
auto pos = std::find_if(v.begin(), v.end(),
[&name](const T& stat) -> bool { return stat->name() == name; });
if (pos == v.end()) {
return nullptr;
}
return *pos;
}

/**
* Find a counter in a stats store.
* @param store supplies the stats store.
Expand Down