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

Unified Diff: net/base/async_host_resolver_unittest.cc

Issue 7466031: AsyncHostResolver: integrated HostCache, temporarily, until we have RR cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comment. Created 9 years, 5 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
Index: net/base/async_host_resolver_unittest.cc
diff --git a/net/base/async_host_resolver_unittest.cc b/net/base/async_host_resolver_unittest.cc
index 0e9298140f492d9202b35695093ad569024ef0e0..ab94cb13ba7ffd780828cf68e1e9693d41eabeb2 100644
--- a/net/base/async_host_resolver_unittest.cc
+++ b/net/base/async_host_resolver_unittest.cc
@@ -38,6 +38,13 @@ void VerifyAddressList(const std::vector<const char*>& ip_addresses,
ASSERT_EQ(static_cast<addrinfo*>(NULL), ainfo);
}
+HostCache* CreateDefaultCache() {
+ return new HostCache(
+ 100, // max cache entries.
+ base::TimeDelta::FromMinutes(1),
+ base::TimeDelta::FromSeconds(0));
+}
+
} // namespace
static const int kPortNum = 80;
@@ -71,7 +78,6 @@ class AsyncHostResolverTest : public testing::Test {
kT3IpAddresses + arraysize(kT3IpAddresses)),
test_prng_(std::deque<int>(
transaction_ids, transaction_ids + arraysize(transaction_ids))) {
-
rand_int_cb_ = base::Bind(&TestPrng::GetNext,
base::Unretained(&test_prng_));
// AF_INET only for now.
@@ -132,7 +138,7 @@ class AsyncHostResolverTest : public testing::Test {
resolver_.reset(
new AsyncHostResolver(
dns_server, kMaxTransactions, kMaxPendingRequests, rand_int_cb_,
- &factory_, NULL));
+ CreateDefaultCache(), &factory_, NULL));
}
protected:
@@ -177,12 +183,28 @@ TEST_F(AsyncHostResolverTest, IPv6LiteralLookup) {
EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
}
-TEST_F(AsyncHostResolverTest, CachedOnlyLookup) {
+TEST_F(AsyncHostResolverTest, CachedLookup) {
info0_.set_only_use_cached_response(true);
- int rv = resolver_->Resolve(info0_, &addrlist0_, &callback0_, NULL,
+ int rv = resolver_->Resolve(info0_, &addrlist0_, NULL, NULL,
BoundNetLog());
- // When caching is added, this should succeed.
EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
+
+ // Cache the result of |info0_| lookup.
+ info0_.set_only_use_cached_response(false);
+ rv = resolver_->Resolve(info0_, &addrlist0_, &callback0_, NULL,
+ BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ rv = callback0_.WaitForResult();
+ EXPECT_EQ(OK, rv);
+ VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_);
+
+ // Now lookup |info0_| from cache only, store results in |addrlist1_|,
cbentzel 2011/07/21 15:31:10 Could you add tests for cache expiration as well?
agayev 2011/07/21 17:48:03 Like creating a cache with 10ms TTL and then sleep
cbentzel 2011/07/21 18:22:15 yeah, you're right.
+ // should succeed synchronously.
+ info0_.set_only_use_cached_response(true);
+ rv = resolver_->Resolve(info0_, &addrlist1_, NULL, NULL,
+ BoundNetLog());
+ EXPECT_EQ(OK, rv);
+ VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_);
}
TEST_F(AsyncHostResolverTest, InvalidHostNameLookup) {

Powered by Google App Engine
This is Rietveld 408576698