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

Unified Diff: net/dns/host_resolver_impl_unittest.cc

Issue 2083643003: DNS: Let requests specify a callback for future cache hits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, add unit test. Created 4 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
« 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 e878667763a15add66936a5118ce754892ea3d84..f201a0811f29b47f3fd761afcc55c4e9510702f7 100644
--- a/net/dns/host_resolver_impl_unittest.cc
+++ b/net/dns/host_resolver_impl_unittest.cc
@@ -2398,4 +2398,61 @@ TEST_F(HostResolverImplTest, ResolveLocalHostname) {
ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses));
}
+void TestCacheHitCallback(int* callback_count,
+ HostResolver::RequestInfo* last_request_info,
+ const HostResolver::RequestInfo& request_info) {
+ ++*callback_count;
+ *last_request_info = request_info;
+}
+
+TEST_F(HostResolverImplTest, CacheHitCallback) {
+ proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42");
+ proc_->SignalMultiple(5u);
+
+ HostResolver::RequestInfo last_request_info(HostPortPair("unassigned", 80));
+
+ // Set a cache hit callback.
+ int count1 = 0;
+ HostResolver::RequestInfo info_callback1(HostPortPair("just.testing", 80));
+ info_callback1.set_cache_hit_callback(
+ base::Bind(&TestCacheHitCallback, &count1, &last_request_info));
+ Request* req = CreateRequest(info_callback1, MEDIUM);
+ EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING));
+ EXPECT_THAT(req->WaitForResult(), IsOk());
+ EXPECT_EQ(0, count1);
+
+ // Make sure the cache hit callback is called, and set another one.
+ // Future requests should call *both* callbacks.
+ int count2 = 0;
+ HostResolver::RequestInfo info_callback2(HostPortPair("just.testing", 80));
+ info_callback2.set_cache_hit_callback(
+ base::Bind(&TestCacheHitCallback, &count2, &last_request_info));
+ req = CreateRequest(info_callback2, MEDIUM);
+ EXPECT_THAT(req->Resolve(), IsOk());
+ EXPECT_EQ(1, count1);
+ EXPECT_EQ(0, count2);
+
+ // Make another request to make sure both callbacks are called.
+ req = CreateRequest("just.testing", 80);
+ EXPECT_THAT(req->Resolve(), IsOk());
+ EXPECT_EQ(2, count1);
+ EXPECT_EQ(1, count2);
+
+ // Make an uncached request to clear the cache hit callbacks.
Charlie Harrison 2016/08/02 17:15:41 Is this because it evicts the entries?
Julia Tuttle 2016/08/02 17:22:50 Yes. Not necessarily *evicts*, really, but certain
+ // It should not call the callbacks itself, since it doesn't hit the cache.
+ HostResolver::RequestInfo info_uncached(HostPortPair("just.testing", 80));
+ info_uncached.set_allow_cached_response(false);
+ req = CreateRequest(info_uncached, MEDIUM);
+ EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING));
+ EXPECT_THAT(req->WaitForResult(), IsOk());
+ EXPECT_EQ(2, count1);
+ EXPECT_EQ(1, count2);
+
+ // Make another request to make sure neither callback is cleared.
Charlie Harrison 2016/08/02 17:15:41 s/neither callback is/both callbacks are/?
Julia Tuttle 2016/08/02 17:22:50 Done.
+ req = CreateRequest("just.testing", 80);
+ EXPECT_THAT(req->Resolve(), IsOk());
+ EXPECT_EQ(2, count1);
+ EXPECT_EQ(1, count2);
+}
+
} // namespace net
« 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