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

Side by Side Diff: net/dns/host_resolver_impl_unittest.cc

Issue 1138833003: Reduce frequency of IPv6 probes in HostResolverImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/log/test_net_log_entry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/synchronization/condition_variable.h" 18 #include "base/synchronization/condition_variable.h"
19 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
20 #include "base/test/test_timeouts.h" 20 #include "base/test/test_timeouts.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "net/base/address_list.h" 22 #include "net/base/address_list.h"
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
25 #include "net/dns/dns_client.h" 25 #include "net/dns/dns_client.h"
26 #include "net/dns/dns_test_util.h" 26 #include "net/dns/dns_test_util.h"
27 #include "net/dns/mock_host_resolver.h" 27 #include "net/dns/mock_host_resolver.h"
28 #include "net/log/test_net_log.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 namespace net { 31 namespace net {
31 32
32 namespace { 33 namespace {
33 34
34 const size_t kMaxJobs = 10u; 35 const size_t kMaxJobs = 10u;
35 const size_t kMaxRetryAttempts = 4u; 36 const size_t kMaxRetryAttempts = 4u;
36 37
37 HostResolver::Options DefaultOptions() { 38 HostResolver::Options DefaultOptions() {
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 524
524 void set_fallback_to_proctask(bool fallback_to_proctask) { 525 void set_fallback_to_proctask(bool fallback_to_proctask) {
525 DCHECK(resolver_.get()); 526 DCHECK(resolver_.get());
526 resolver_->fallback_to_proctask_ = fallback_to_proctask; 527 resolver_->fallback_to_proctask_ = fallback_to_proctask;
527 } 528 }
528 529
529 static unsigned maximum_dns_failures() { 530 static unsigned maximum_dns_failures() {
530 return HostResolverImpl::kMaximumDnsFailures; 531 return HostResolverImpl::kMaximumDnsFailures;
531 } 532 }
532 533
534 bool IsIPv6Reachable(const BoundNetLog& net_log) {
535 return resolver_->IsIPv6Reachable(net_log);
536 }
537
533 scoped_refptr<MockHostResolverProc> proc_; 538 scoped_refptr<MockHostResolverProc> proc_;
534 scoped_ptr<HostResolverImpl> resolver_; 539 scoped_ptr<HostResolverImpl> resolver_;
535 ScopedVector<Request> requests_; 540 ScopedVector<Request> requests_;
536 541
537 scoped_ptr<Handler> handler_; 542 scoped_ptr<Handler> handler_;
538 }; 543 };
539 544
540 TEST_F(HostResolverImplTest, AsynchronousLookup) { 545 TEST_F(HostResolverImplTest, AsynchronousLookup) {
541 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); 546 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42");
542 proc_->SignalMultiple(1u); 547 proc_->SignalMultiple(1u);
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 1395
1391 request = CreateRequest("not_reserved2"); 1396 request = CreateRequest("not_reserved2");
1392 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); 1397 EXPECT_EQ(ERR_IO_PENDING, request->Resolve());
1393 EXPECT_EQ(OK, request->WaitForResult()); 1398 EXPECT_EQ(OK, request->WaitForResult());
1394 1399
1395 request = CreateRequest("not_reserved3"); 1400 request = CreateRequest("not_reserved3");
1396 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); 1401 EXPECT_EQ(ERR_IO_PENDING, request->Resolve());
1397 EXPECT_EQ(OK, request->WaitForResult()); 1402 EXPECT_EQ(OK, request->WaitForResult());
1398 } 1403 }
1399 1404
1405 TEST_F(HostResolverImplTest, IsIPv6Reachable) {
1406 // Verify that two consecutive calls return the same value.
1407 TestNetLog net_log;
1408 BoundNetLog bound_net_log = BoundNetLog::Make(&net_log, NetLog::SOURCE_NONE);
1409 bool result1 = IsIPv6Reachable(bound_net_log);
1410 bool result2 = IsIPv6Reachable(bound_net_log);
1411 EXPECT_EQ(result1, result2);
1412
1413 // Filter reachability check events and verify that there are two of them.
1414 TestNetLogEntry::List event_list;
1415 net_log.GetEntries(&event_list);
1416 TestNetLogEntry::List probe_event_list;
1417 for (const auto& event : event_list) {
1418 if (event.type == NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK) {
1419 probe_event_list.push_back(event);
1420 }
1421 }
1422 ASSERT_EQ(2U, probe_event_list.size());
1423
1424 // Verify that the first request was not cached and the second one was.
1425 bool cached;
1426 EXPECT_TRUE(probe_event_list[0].GetBooleanValue("cached", &cached));
1427 EXPECT_FALSE(cached);
1428 EXPECT_TRUE(probe_event_list[1].GetBooleanValue("cached", &cached));
1429 EXPECT_TRUE(cached);
1430 }
1431
1400 DnsConfig CreateValidDnsConfig() { 1432 DnsConfig CreateValidDnsConfig() {
1401 IPAddressNumber dns_ip; 1433 IPAddressNumber dns_ip;
1402 bool rv = ParseIPLiteralToNumber("192.168.1.0", &dns_ip); 1434 bool rv = ParseIPLiteralToNumber("192.168.1.0", &dns_ip);
1403 EXPECT_TRUE(rv); 1435 EXPECT_TRUE(rv);
1404 1436
1405 DnsConfig config; 1437 DnsConfig config;
1406 config.nameservers.push_back(IPEndPoint(dns_ip, dns_protocol::kDefaultPort)); 1438 config.nameservers.push_back(IPEndPoint(dns_ip, dns_protocol::kDefaultPort));
1407 EXPECT_TRUE(config.IsValid()); 1439 EXPECT_TRUE(config.IsValid());
1408 return config; 1440 return config;
1409 } 1441 }
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 2206
2175 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 2207 EXPECT_EQ(OK, requests_[0]->WaitForResult());
2176 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); 2208 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
2177 EXPECT_EQ(OK, requests_[1]->WaitForResult()); 2209 EXPECT_EQ(OK, requests_[1]->WaitForResult());
2178 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); 2210 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80));
2179 EXPECT_EQ(OK, requests_[2]->WaitForResult()); 2211 EXPECT_EQ(OK, requests_[2]->WaitForResult());
2180 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); 2212 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80));
2181 } 2213 }
2182 2214
2183 } // namespace net 2215 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/log/test_net_log_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698