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

Unified Diff: net/dns/host_resolver_impl_unittest.cc

Issue 1903263002: DNS: Expose stale results through HostResolverImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dns_stale1
Patch Set: Remove ResolveStaleFromCache from HostResolver but not Impl Created 4 years, 6 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/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_impl_unittest.cc
diff --git a/net/dns/host_resolver_impl_unittest.cc b/net/dns/host_resolver_impl_unittest.cc
index ff840d9ddb3c3784c2c2996a193f63c0e32b9993..210b36dfdc0773c2c980320fb8d40006a96dca4c 100644
--- a/net/dns/host_resolver_impl_unittest.cc
+++ b/net/dns/host_resolver_impl_unittest.cc
@@ -211,7 +211,7 @@ class Request {
Request(const HostResolver::RequestInfo& info,
RequestPriority priority,
size_t index,
- HostResolver* resolver,
+ HostResolverImpl* resolver,
Handler* handler)
: info_(info),
priority_(priority),
@@ -244,6 +244,13 @@ class Request {
return resolver_->ResolveFromCache(info_, &list_, BoundNetLog());
}
+ int ResolveStaleFromCache() {
+ DCHECK(resolver_);
+ DCHECK(!handle_);
+ return resolver_->ResolveStaleFromCache(info_, &list_, &staleness_,
+ BoundNetLog());
+ }
+
void ChangePriority(RequestPriority priority) {
DCHECK(resolver_);
DCHECK(handle_);
@@ -262,6 +269,7 @@ class Request {
size_t index() const { return index_; }
const AddressList& list() const { return list_; }
int result() const { return result_; }
+ const HostCache::EntryStaleness staleness() const { return staleness_; }
bool completed() const { return result_ != ERR_IO_PENDING; }
bool pending() const { return handle_ != NULL; }
@@ -318,13 +326,14 @@ class Request {
HostResolver::RequestInfo info_;
RequestPriority priority_;
size_t index_;
- HostResolver* resolver_;
+ HostResolverImpl* resolver_;
Handler* handler_;
bool quit_on_complete_;
AddressList list_;
int result_;
HostResolver::RequestHandle handle_;
+ HostCache::EntryStaleness staleness_;
DISALLOW_COPY_AND_ASSIGN(Request);
};
@@ -605,6 +614,11 @@ class HostResolverImplTest : public testing::Test {
return resolver_->IsIPv6Reachable(net_log);
}
+ void MakeCacheStale() {
+ DCHECK(resolver_.get());
+ resolver_->GetHostCache()->OnNetworkChange();
+ }
+
scoped_refptr<MockHostResolverProc> proc_;
std::unique_ptr<HostResolverImpl> resolver_;
std::vector<std::unique_ptr<Request>> requests_;
@@ -1379,6 +1393,38 @@ TEST_F(HostResolverImplTest, ResolveFromCache) {
EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.1.42", 80));
}
+TEST_F(HostResolverImplTest, ResolveStaleFromCache) {
+ proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42");
+ proc_->SignalMultiple(1u); // Need only one.
+
+ HostResolver::RequestInfo info(HostPortPair("just.testing", 80));
+
+ // First hit will miss the cache.
+ EXPECT_EQ(ERR_DNS_CACHE_MISS,
+ CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache());
+
+ // This time, we fetch normally.
+ EXPECT_EQ(ERR_IO_PENDING, CreateRequest(info, DEFAULT_PRIORITY)->Resolve());
+ EXPECT_EQ(OK, requests_[1]->WaitForResult());
+
+ // Now we should be able to fetch from the cache.
+ EXPECT_EQ(OK, CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache());
+ EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.1.42", 80));
+ EXPECT_EQ(OK, CreateRequest(info, DEFAULT_PRIORITY)->ResolveStaleFromCache());
+ EXPECT_TRUE(requests_[3]->HasOneAddress("192.168.1.42", 80));
+ EXPECT_FALSE(requests_[3]->staleness().is_stale());
+
+ MakeCacheStale();
+
+ // Now we should be able to fetch from the cache only if we use
+ // ResolveStaleFromCache.
+ EXPECT_EQ(ERR_DNS_CACHE_MISS,
+ CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache());
+ EXPECT_EQ(OK, CreateRequest(info, DEFAULT_PRIORITY)->ResolveStaleFromCache());
+ EXPECT_TRUE(requests_[5]->HasOneAddress("192.168.1.42", 80));
+ EXPECT_TRUE(requests_[5]->staleness().is_stale());
+}
+
// Test the retry attempts simulating host resolver proc that takes too long.
TEST_F(HostResolverImplTest, MultipleAttempts) {
// Total number of attempts would be 3 and we want the 3rd attempt to resolve
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698