From 1db4a096d427892a0123d876618a38b7e162b001 Mon Sep 17 00:00:00 2001 From: Adam Singer Date: Tue, 27 Nov 2018 10:46:26 -0800 Subject: [PATCH] Test mapping of Histograms and HistogramsNameMap (#4720) Summary: Adding sanity check test for mapping of `Histograms` and `HistogramsNameMap` ``` [==========] Running 2 tests from 1 test case. [----------] Global test environment set-up. [----------] 2 tests from StatisticsTest [ RUN ] StatisticsTest.SanityTickers [ OK ] StatisticsTest.SanityTickers (0 ms) [ RUN ] StatisticsTest.SanityHistograms [ OK ] StatisticsTest.SanityHistograms (0 ms) [----------] 2 tests from StatisticsTest (0 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (0 ms total) [ PASSED ] 2 tests. ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/4720 Differential Revision: D13217061 Pulled By: ajkr fbshipit-source-id: 6427f4e684c36b2f3c3440808b74fee86a364683 --- include/rocksdb/statistics.h | 2 +- monitoring/statistics_test.cc | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/rocksdb/statistics.h b/include/rocksdb/statistics.h index 9b5294079..14e6195fa 100644 --- a/include/rocksdb/statistics.h +++ b/include/rocksdb/statistics.h @@ -414,7 +414,7 @@ enum Histograms : uint32_t { // Time spent flushing memtable to disk FLUSH_TIME, - HISTOGRAM_ENUM_MAX, // TODO(ldemailly): enforce HistogramsNameMap match + HISTOGRAM_ENUM_MAX, }; extern const std::vector> HistogramsNameMap; diff --git a/monitoring/statistics_test.cc b/monitoring/statistics_test.cc index 43aacde9c..a77022bfb 100644 --- a/monitoring/statistics_test.cc +++ b/monitoring/statistics_test.cc @@ -16,7 +16,7 @@ class StatisticsTest : public testing::Test {}; // Sanity check to make sure that contents and order of TickersNameMap // match Tickers enum -TEST_F(StatisticsTest, Sanity) { +TEST_F(StatisticsTest, SanityTickers) { EXPECT_EQ(static_cast(Tickers::TICKER_ENUM_MAX), TickersNameMap.size()); @@ -26,6 +26,18 @@ TEST_F(StatisticsTest, Sanity) { } } +// Sanity check to make sure that contents and order of HistogramsNameMap +// match Tickers enum +TEST_F(StatisticsTest, SanityHistograms) { + EXPECT_EQ(static_cast(Histograms::HISTOGRAM_ENUM_MAX), + HistogramsNameMap.size()); + + for (uint32_t h = 0; h < Histograms::HISTOGRAM_ENUM_MAX; h++) { + auto pair = HistogramsNameMap[static_cast(h)]; + ASSERT_EQ(pair.first, h) << "Miss match at " << pair.second; + } +} + } // namespace rocksdb int main(int argc, char** argv) {