Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(874)

Unified Diff: net/sdch/sdch_owner_unittest.cc

Issue 1051353003: SDCH: add TimeWeightedMemoryUse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't reset clock Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/sdch/sdch_owner.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/sdch/sdch_owner_unittest.cc
diff --git a/net/sdch/sdch_owner_unittest.cc b/net/sdch/sdch_owner_unittest.cc
index ebcbd02b3d358dddfa4206ea4655ada12c69c7d4..3ca8a2cf539c68c7d38b8590356882762fa62b71 100644
--- a/net/sdch/sdch_owner_unittest.cc
+++ b/net/sdch/sdch_owner_unittest.cc
@@ -6,6 +6,7 @@
#include "base/prefs/testing_pref_store.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
+#include "base/test/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/values.h"
#include "net/base/net_log.h"
@@ -254,18 +255,18 @@ class SdchOwnerTest : public testing::Test {
: last_jobs_created_(error_jobs_created),
dictionary_creation_index_(0),
pref_store_(new TestingPrefStore),
- sdch_owner_(&sdch_manager_, &url_request_context_) {
+ sdch_owner_(new SdchOwner(&sdch_manager_, &url_request_context_)) {
// Any jobs created on this context will immediately error,
// which leaves the test in control of signals to SdchOwner.
url_request_context_.set_job_factory(&job_factory_);
// Reduce sizes to reduce time for string operations.
- sdch_owner_.SetMaxTotalDictionarySize(kMaxSizeForTesting);
- sdch_owner_.SetMinSpaceForDictionaryFetch(kMinFetchSpaceForTesting);
+ sdch_owner_->SetMaxTotalDictionarySize(kMaxSizeForTesting);
+ sdch_owner_->SetMinSpaceForDictionaryFetch(kMinFetchSpaceForTesting);
}
SdchManager& sdch_manager() { return sdch_manager_; }
- SdchOwner& sdch_owner() { return sdch_owner_; }
+ SdchOwner& sdch_owner() { return *(sdch_owner_.get()); }
BoundNetLog& bound_net_log() { return net_log_; }
TestingPrefStore& pref_store() { return *(pref_store_.get()); }
@@ -325,6 +326,10 @@ class SdchOwnerTest : public testing::Test {
return DictionaryPresentInManager(server_hash);
}
+ void ResetOwner() {
+ sdch_owner_.reset(new SdchOwner(&sdch_manager_, &url_request_context_));
+ }
+
private:
int last_jobs_created_;
BoundNetLog net_log_;
@@ -337,7 +342,7 @@ class SdchOwnerTest : public testing::Test {
URLRequestContext url_request_context_;
SdchManager sdch_manager_;
scoped_refptr<TestingPrefStore> pref_store_;
- SdchOwner sdch_owner_;
+ scoped_ptr<SdchOwner> sdch_owner_;
DISALLOW_COPY_AND_ASSIGN(SdchOwnerTest);
};
@@ -401,10 +406,15 @@ TEST_F(SdchOwnerTest, OnDictionaryFetched_Fetching) {
// Confirm auto-eviction happens if space is needed.
TEST_F(SdchOwnerTest, ConfirmAutoEviction) {
+ base::Time start_time = base::Time::Now();
std::string server_hash_d1;
std::string server_hash_d2;
std::string server_hash_d3;
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ sdch_owner().SetClockForTesting(make_scoped_ptr(test_clock));
+ test_clock->SetNow(base::Time::Now());
+
// Add two dictionaries, one recent, one more than a day in the past.
base::Time fresh(base::Time::Now() - base::TimeDelta::FromHours(23));
base::Time stale(base::Time::Now() - base::TimeDelta::FromHours(25));
@@ -417,11 +427,41 @@ TEST_F(SdchOwnerTest, ConfirmAutoEviction) {
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2));
+ base::HistogramTester tester;
+ const base::TimeDelta synthetic_delta = base::TimeDelta::FromSeconds(5);
+
+ test_clock->Advance(synthetic_delta);
+
EXPECT_TRUE(
CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d3, fresh));
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2));
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3));
+
+ base::TimeDelta expected_proc_lifetime = synthetic_delta * 3 +
+ base::Time::Now() - start_time;
+ size_t expected_value_base = ((kMaxSizeForTesting / 2) *
+ synthetic_delta.InMilliseconds()) /
+ expected_proc_lifetime.InMilliseconds();
+
+ const char *kHistogram = "Sdch3.TimeWeightedMemoryUse";
+ tester.ExpectTotalCount(kHistogram, 0);
+
+ // Dictionary insertions and deletions:
+ // T = 0: insert d1 and d2
+ // T = 5: insert d3, which evicts d2
+ // T = 15: destroy SdchOwner, which evicts d1 and d3
+ // Therefore, d2's lifetime is synthetic_delta, d1's is synthetic_delta * 3,
+ // and d3's is synthetic_delta * 2. The expected_value_base variable is the
+ // base factor for d2's memory consumption, of which d1's and d3's are
+ // multiples.
+ test_clock->Advance(synthetic_delta * 2);
+ ResetOwner();
+
+ tester.ExpectTotalCount(kHistogram, 3);
+ tester.ExpectBucketCount(kHistogram, expected_value_base, 1);
+ tester.ExpectBucketCount(kHistogram, expected_value_base * 2, 1);
+ tester.ExpectBucketCount(kHistogram, expected_value_base * 3, 1);
}
// Confirm auto-eviction happens if space is needed, with a more complicated
« no previous file with comments | « net/sdch/sdch_owner.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698