diff options
author | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 21:14:21 +0000 |
---|---|---|
committer | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 21:14:21 +0000 |
commit | 6a7dfb3cd638829a04e002ea9bc5b18ed3c9c03f (patch) | |
tree | 51028572b1a54200e108c954c74d4a8fc98558d6 /net | |
parent | b639a833a5f3533509a85bb45c407297b6aa82d2 (diff) | |
download | chromium_src-6a7dfb3cd638829a04e002ea9bc5b18ed3c9c03f.zip chromium_src-6a7dfb3cd638829a04e002ea9bc5b18ed3c9c03f.tar.gz chromium_src-6a7dfb3cd638829a04e002ea9bc5b18ed3c9c03f.tar.bz2 |
Revert 242121 "Reland "Add a HistogramRecorder class and use cas..."
As per request from lpromero, reverting since it might be failing a
test - see
http://build.chromium.org/p/chromium.memory.fyi/builders/Windows%20Tests%20%28tsan%29/builds/17153/steps/memory%20test%3A%20base_unittests/logs/stdio
[ RUN ] HistogramTest.BasicTest
[3824:2780:1220/111332:4747750:FATAL:statistics_recorder.cc(270)] Check failed: !histograms_.
TBR=lpromero@chromium.org
> Reland "Add a HistogramRecorder class and use cases."
>
> This CL adds a utility class to streamline the task of testing that metrics have been updated as expected. Specifically, the HistogramRecorder class allows a client to obtain the differential value of a given histogram in the interval since the given HistogramRecorder instance was created.
>
> This reverts commit b957026f43ef9464a8cdd5a240867c807b2281da.
>
> BUG=232414
> TBR=rsleevi, mark, groby, thakis
>
> Review URL: https://codereview.chromium.org/19866004
TBR=lpromero@chromium.org
Review URL: https://codereview.chromium.org/120273002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242176 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/url_request/url_request_throttler_unittest.cc | 82 |
1 files changed, 64 insertions, 18 deletions
diff --git a/net/url_request/url_request_throttler_unittest.cc b/net/url_request/url_request_throttler_unittest.cc index 52b3a0a..b964b10 100644 --- a/net/url_request/url_request_throttler_unittest.cc +++ b/net/url_request/url_request_throttler_unittest.cc @@ -5,12 +5,13 @@ #include "net/url_request/url_request_throttler_manager.h" #include "base/memory/scoped_ptr.h" +#include "base/metrics/histogram.h" #include "base/metrics/histogram_samples.h" +#include "base/metrics/statistics_recorder.h" #include "base/pickle.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" -#include "base/test/histogram_recorder.h" #include "base/time/time.h" #include "net/base/load_flags.h" #include "net/base/request_priority.h" @@ -28,7 +29,10 @@ namespace net { namespace { -const char kRequestThrottledHistogramName[] = "Throttling.RequestThrottled"; +using base::Histogram; +using base::HistogramBase; +using base::HistogramSamples; +using base::StatisticsRecorder; class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { public: @@ -172,22 +176,32 @@ class URLRequestThrottlerEntryTest : public testing::Test { URLRequestThrottlerEntryTest() : request_(GURL(), DEFAULT_PRIORITY, NULL, &context_) {} - static void SetUpTestCase() { - base::HistogramRecorder::Initialize(); - } - virtual void SetUp(); + virtual void TearDown(); + + // After calling this function, histogram snapshots in |samples_| contain + // only the delta caused by the test case currently running. + void CalculateHistogramDeltas(); TimeTicks now_; MockURLRequestThrottlerManager manager_; // Dummy object, not used. scoped_refptr<MockURLRequestThrottlerEntry> entry_; - scoped_ptr<base::HistogramRecorder> histogram_recorder_; + std::map<std::string, HistogramSamples*> original_samples_; + std::map<std::string, HistogramSamples*> samples_; TestURLRequestContext context_; TestURLRequest request_; }; +// List of all histograms we care about in these unit tests. +const char* kHistogramNames[] = { + "Throttling.FailureCountAtSuccess", + "Throttling.PerceivedDowntime", + "Throttling.RequestThrottled", + "Throttling.SiteOptedOut", +}; + void URLRequestThrottlerEntryTest::SetUp() { request_.SetLoadFlags(0); @@ -195,7 +209,43 @@ void URLRequestThrottlerEntryTest::SetUp() { entry_ = new MockURLRequestThrottlerEntry(&manager_); entry_->ResetToBlank(now_); - histogram_recorder_.reset(new base::HistogramRecorder()); + for (size_t i = 0; i < arraysize(kHistogramNames); ++i) { + // Must retrieve original samples for each histogram for comparison + // as other tests may affect them. + const char* name = kHistogramNames[i]; + HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); + if (histogram) { + original_samples_[name] = histogram->SnapshotSamples().release(); + } else { + original_samples_[name] = NULL; + } + } +} + +void URLRequestThrottlerEntryTest::TearDown() { + STLDeleteValues(&original_samples_); + STLDeleteValues(&samples_); +} + +void URLRequestThrottlerEntryTest::CalculateHistogramDeltas() { + for (size_t i = 0; i < arraysize(kHistogramNames); ++i) { + const char* name = kHistogramNames[i]; + HistogramSamples* original = original_samples_[name]; + + HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); + if (histogram) { + ASSERT_EQ(HistogramBase::kUmaTargetedHistogramFlag, histogram->flags()); + + scoped_ptr<HistogramSamples> samples(histogram->SnapshotSamples()); + if (original) + samples->Subtract(*original); + samples_[name] = samples.release(); + } + } + + // Ensure we don't accidentally use the originals in our tests. + STLDeleteValues(&original_samples_); + original_samples_.clear(); } std::ostream& operator<<(std::ostream& out, const base::TimeTicks& time) { @@ -223,11 +273,9 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) { request_.SetLoadFlags(LOAD_MAYBE_USER_GESTURE); EXPECT_FALSE(entry_->ShouldRejectRequest(request_)); - scoped_ptr<base::HistogramSamples> samples( - histogram_recorder_->GetHistogramSamplesSinceCreation( - kRequestThrottledHistogramName)); - ASSERT_EQ(1, samples->GetCount(0)); - ASSERT_EQ(1, samples->GetCount(1)); + CalculateHistogramDeltas(); + ASSERT_EQ(1, samples_["Throttling.RequestThrottled"]->GetCount(0)); + ASSERT_EQ(1, samples_["Throttling.RequestThrottled"]->GetCount(1)); } TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) { @@ -237,11 +285,9 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) { entry_->fake_time_now_ - TimeDelta::FromMilliseconds(1)); EXPECT_FALSE(entry_->ShouldRejectRequest(request_)); - scoped_ptr<base::HistogramSamples> samples( - histogram_recorder_->GetHistogramSamplesSinceCreation( - kRequestThrottledHistogramName)); - ASSERT_EQ(2, samples->GetCount(0)); - ASSERT_EQ(0, samples->GetCount(1)); + CalculateHistogramDeltas(); + ASSERT_EQ(2, samples_["Throttling.RequestThrottled"]->GetCount(0)); + ASSERT_EQ(0, samples_["Throttling.RequestThrottled"]->GetCount(1)); } TEST_F(URLRequestThrottlerEntryTest, InterfaceUpdateFailure) { |