| OLD | NEW |
| 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/host_cache.h" | |
| 28 #include "net/dns/mock_host_resolver.h" | 27 #include "net/dns/mock_host_resolver.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 29 |
| 31 namespace net { | 30 namespace net { |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 const size_t kMaxJobs = 10u; | 34 const size_t kMaxJobs = 10u; |
| 36 const size_t kMaxRetryAttempts = 4u; | 35 const size_t kMaxRetryAttempts = 4u; |
| 37 | 36 |
| 38 PrioritizedDispatcher::Limits DefaultLimits() { | 37 HostResolver::Options DefaultOptions() { |
| 39 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, kMaxJobs); | 38 HostResolver::Options options; |
| 40 return limits; | 39 options.max_concurrent_resolves = kMaxJobs; |
| 40 options.max_retry_attempts = kMaxRetryAttempts; |
| 41 options.enable_caching = true; |
| 42 return options; |
| 41 } | 43 } |
| 42 | 44 |
| 43 HostResolverImpl::ProcTaskParams DefaultParams( | 45 HostResolverImpl::ProcTaskParams DefaultParams( |
| 44 HostResolverProc* resolver_proc) { | 46 HostResolverProc* resolver_proc) { |
| 45 return HostResolverImpl::ProcTaskParams(resolver_proc, kMaxRetryAttempts); | 47 return HostResolverImpl::ProcTaskParams(resolver_proc, kMaxRetryAttempts); |
| 46 } | 48 } |
| 47 | 49 |
| 48 // A HostResolverProc that pushes each host mapped into a list and allows | 50 // A HostResolverProc that pushes each host mapped into a list and allows |
| 49 // waiting for a specific number of requests. Unlike RuleBasedHostResolverProc | 51 // waiting for a specific number of requests. Unlike RuleBasedHostResolverProc |
| 50 // it never calls SystemHostResolverCall. By default resolves all hostnames to | 52 // it never calls SystemHostResolverCall. By default resolves all hostnames to |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 417 |
| 416 } // namespace | 418 } // namespace |
| 417 | 419 |
| 418 class HostResolverImplTest : public testing::Test { | 420 class HostResolverImplTest : public testing::Test { |
| 419 public: | 421 public: |
| 420 static const int kDefaultPort = 80; | 422 static const int kDefaultPort = 80; |
| 421 | 423 |
| 422 HostResolverImplTest() : proc_(new MockHostResolverProc()) {} | 424 HostResolverImplTest() : proc_(new MockHostResolverProc()) {} |
| 423 | 425 |
| 424 void CreateResolver() { | 426 void CreateResolver() { |
| 425 CreateResolverWithLimitsAndParams(DefaultLimits(), | 427 CreateResolverWithLimitsAndParams(kMaxJobs, |
| 426 DefaultParams(proc_.get())); | 428 DefaultParams(proc_.get())); |
| 427 } | 429 } |
| 428 | 430 |
| 429 // This HostResolverImpl will only allow 1 outstanding resolve at a time and | 431 // This HostResolverImpl will only allow 1 outstanding resolve at a time and |
| 430 // perform no retries. | 432 // perform no retries. |
| 431 void CreateSerialResolver() { | 433 void CreateSerialResolver() { |
| 432 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get()); | 434 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get()); |
| 433 params.max_retry_attempts = 0u; | 435 params.max_retry_attempts = 0u; |
| 434 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); | 436 CreateResolverWithLimitsAndParams(1u, params); |
| 435 CreateResolverWithLimitsAndParams(limits, params); | |
| 436 } | 437 } |
| 437 | 438 |
| 438 protected: | 439 protected: |
| 439 // A Request::Handler which is a proxy to the HostResolverImplTest fixture. | 440 // A Request::Handler which is a proxy to the HostResolverImplTest fixture. |
| 440 struct Handler : public Request::Handler { | 441 struct Handler : public Request::Handler { |
| 441 virtual ~Handler() {} | 442 virtual ~Handler() {} |
| 442 | 443 |
| 443 // Proxy functions so that classes derived from Handler can access them. | 444 // Proxy functions so that classes derived from Handler can access them. |
| 444 Request* CreateRequest(const HostResolver::RequestInfo& info, | 445 Request* CreateRequest(const HostResolver::RequestInfo& info, |
| 445 RequestPriority priority) { | 446 RequestPriority priority) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 463 CreateResolver(); | 464 CreateResolver(); |
| 464 } | 465 } |
| 465 | 466 |
| 466 virtual void TearDown() OVERRIDE { | 467 virtual void TearDown() OVERRIDE { |
| 467 if (resolver_.get()) | 468 if (resolver_.get()) |
| 468 EXPECT_EQ(0u, resolver_->num_running_dispatcher_jobs_for_tests()); | 469 EXPECT_EQ(0u, resolver_->num_running_dispatcher_jobs_for_tests()); |
| 469 EXPECT_FALSE(proc_->HasBlockedRequests()); | 470 EXPECT_FALSE(proc_->HasBlockedRequests()); |
| 470 } | 471 } |
| 471 | 472 |
| 472 virtual void CreateResolverWithLimitsAndParams( | 473 virtual void CreateResolverWithLimitsAndParams( |
| 473 const PrioritizedDispatcher::Limits& limits, | 474 size_t max_concurrent_resolves, |
| 474 const HostResolverImpl::ProcTaskParams& params) { | 475 const HostResolverImpl::ProcTaskParams& params) { |
| 475 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), | 476 HostResolverImpl::Options options = DefaultOptions(); |
| 476 limits, params, NULL)); | 477 options.max_concurrent_resolves = max_concurrent_resolves; |
| 478 resolver_.reset(new HostResolverImpl(options, NULL)); |
| 479 resolver_->set_proc_params_for_test(params); |
| 477 } | 480 } |
| 478 | 481 |
| 479 // The Request will not be made until a call to |Resolve()|, and the Job will | 482 // The Request will not be made until a call to |Resolve()|, and the Job will |
| 480 // not start until released by |proc_->SignalXXX|. | 483 // not start until released by |proc_->SignalXXX|. |
| 481 Request* CreateRequest(const HostResolver::RequestInfo& info, | 484 Request* CreateRequest(const HostResolver::RequestInfo& info, |
| 482 RequestPriority priority) { | 485 RequestPriority priority) { |
| 483 Request* req = new Request( | 486 Request* req = new Request( |
| 484 info, priority, requests_.size(), resolver_.get(), handler_.get()); | 487 info, priority, requests_.size(), resolver_.get(), handler_.get()); |
| 485 requests_.push_back(req); | 488 requests_.push_back(req); |
| 486 return req; | 489 return req; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 if (req->index() == 0) { | 831 if (req->index() == 0) { |
| 829 // On completing the first request, start another request for "a". | 832 // On completing the first request, start another request for "a". |
| 830 // Since caching is disabled, this will result in another async request. | 833 // Since caching is disabled, this will result in another async request. |
| 831 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve()); | 834 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve()); |
| 832 } | 835 } |
| 833 } | 836 } |
| 834 }; | 837 }; |
| 835 set_handler(new MyHandler()); | 838 set_handler(new MyHandler()); |
| 836 | 839 |
| 837 // Turn off caching for this host resolver. | 840 // Turn off caching for this host resolver. |
| 838 resolver_.reset(new HostResolverImpl(scoped_ptr<HostCache>(), | 841 HostResolver::Options options = DefaultOptions(); |
| 839 DefaultLimits(), | 842 options.enable_caching = false; |
| 840 DefaultParams(proc_.get()), | 843 resolver_.reset(new HostResolverImpl(options, NULL)); |
| 841 NULL)); | 844 resolver_->set_proc_params_for_test(DefaultParams(proc_.get())); |
| 842 | 845 |
| 843 for (size_t i = 0; i < 4; ++i) { | 846 for (size_t i = 0; i < 4; ++i) { |
| 844 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; | 847 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; |
| 845 } | 848 } |
| 846 | 849 |
| 847 proc_->SignalMultiple(2u); // One for "a". One for the second "a". | 850 proc_->SignalMultiple(2u); // One for "a". One for the second "a". |
| 848 | 851 |
| 849 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 852 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
| 850 ASSERT_EQ(5u, requests_.size()); | 853 ASSERT_EQ(5u, requests_.size()); |
| 851 EXPECT_EQ(OK, requests_.back()->WaitForResult()); | 854 EXPECT_EQ(OK, requests_.back()->WaitForResult()); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 new LookupAttemptHostResolverProc( | 1268 new LookupAttemptHostResolverProc( |
| 1266 NULL, kAttemptNumberToResolve, kTotalAttempts)); | 1269 NULL, kAttemptNumberToResolve, kTotalAttempts)); |
| 1267 | 1270 |
| 1268 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc.get()); | 1271 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc.get()); |
| 1269 | 1272 |
| 1270 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so | 1273 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so |
| 1271 // that unit test runs faster. For example, this test finishes in 1.5 secs | 1274 // that unit test runs faster. For example, this test finishes in 1.5 secs |
| 1272 // (500ms * 3). | 1275 // (500ms * 3). |
| 1273 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500); | 1276 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500); |
| 1274 | 1277 |
| 1275 resolver_.reset( | 1278 resolver_.reset(new HostResolverImpl(DefaultOptions(), NULL)); |
| 1276 new HostResolverImpl(HostCache::CreateDefaultCache(), | 1279 resolver_->set_proc_params_for_test(params); |
| 1277 DefaultLimits(), | |
| 1278 params, | |
| 1279 NULL)); | |
| 1280 | 1280 |
| 1281 // Resolve "host1". | 1281 // Resolve "host1". |
| 1282 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1282 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
| 1283 Request* req = CreateRequest(info, DEFAULT_PRIORITY); | 1283 Request* req = CreateRequest(info, DEFAULT_PRIORITY); |
| 1284 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1284 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 1285 | 1285 |
| 1286 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. | 1286 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. |
| 1287 EXPECT_EQ(-4, req->WaitForResult()); | 1287 EXPECT_EQ(-4, req->WaitForResult()); |
| 1288 | 1288 |
| 1289 resolver_proc->WaitForAllAttemptsToFinish( | 1289 resolver_proc->WaitForAllAttemptsToFinish( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 false); | 1346 false); |
| 1347 AddDnsRule("4slow_6timeout", dns_protocol::kTypeA, | 1347 AddDnsRule("4slow_6timeout", dns_protocol::kTypeA, |
| 1348 MockDnsClientRule::OK, true); | 1348 MockDnsClientRule::OK, true); |
| 1349 AddDnsRule("4slow_6timeout", dns_protocol::kTypeAAAA, | 1349 AddDnsRule("4slow_6timeout", dns_protocol::kTypeAAAA, |
| 1350 MockDnsClientRule::TIMEOUT, false); | 1350 MockDnsClientRule::TIMEOUT, false); |
| 1351 CreateResolver(); | 1351 CreateResolver(); |
| 1352 } | 1352 } |
| 1353 | 1353 |
| 1354 // HostResolverImplTest implementation: | 1354 // HostResolverImplTest implementation: |
| 1355 virtual void CreateResolverWithLimitsAndParams( | 1355 virtual void CreateResolverWithLimitsAndParams( |
| 1356 const PrioritizedDispatcher::Limits& limits, | 1356 size_t max_concurrent_resolves, |
| 1357 const HostResolverImpl::ProcTaskParams& params) OVERRIDE { | 1357 const HostResolverImpl::ProcTaskParams& params) OVERRIDE { |
| 1358 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), | 1358 HostResolverImpl::Options options = DefaultOptions(); |
| 1359 limits, | 1359 options.max_concurrent_resolves = max_concurrent_resolves; |
| 1360 params, | 1360 resolver_.reset(new HostResolverImpl(options, NULL)); |
| 1361 NULL)); | 1361 resolver_->set_proc_params_for_test(params); |
| 1362 // Disable IPv6 support probing. | 1362 // Disable IPv6 support probing. |
| 1363 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); | 1363 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1364 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_); | 1364 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_); |
| 1365 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_)); | 1365 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_)); |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. | 1368 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. |
| 1369 void AddDnsRule(const std::string& prefix, | 1369 void AddDnsRule(const std::string& prefix, |
| 1370 uint16 qtype, | 1370 uint16 qtype, |
| 1371 MockDnsClientRule::Result result, | 1371 MockDnsClientRule::Result result, |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1681 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 1682 EXPECT_EQ(OK, req->WaitForResult()); | 1682 EXPECT_EQ(OK, req->WaitForResult()); |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 // Confirm that resolving "localhost" is unrestricted even if there are no | 1685 // Confirm that resolving "localhost" is unrestricted even if there are no |
| 1686 // global IPv6 address. See SystemHostResolverCall for rationale. | 1686 // global IPv6 address. See SystemHostResolverCall for rationale. |
| 1687 // Test both the DnsClient and system host resolver paths. | 1687 // Test both the DnsClient and system host resolver paths. |
| 1688 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { | 1688 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { |
| 1689 // Use regular SystemHostResolverCall! | 1689 // Use regular SystemHostResolverCall! |
| 1690 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); | 1690 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); |
| 1691 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), | 1691 resolver_.reset(new HostResolverImpl(DefaultOptions(), NULL)); |
| 1692 DefaultLimits(), | 1692 resolver_->set_proc_params_for_test(DefaultParams(proc.get())); |
| 1693 DefaultParams(proc.get()), | 1693 |
| 1694 NULL)); | |
| 1695 resolver_->SetDnsClient( | 1694 resolver_->SetDnsClient( |
| 1696 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); | 1695 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); |
| 1697 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1696 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1698 | 1697 |
| 1699 // Get the expected output. | 1698 // Get the expected output. |
| 1700 AddressList addrlist; | 1699 AddressList addrlist; |
| 1701 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, | 1700 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, |
| 1702 NULL); | 1701 NULL); |
| 1703 if (rv != OK) | 1702 if (rv != OK) |
| 1704 return; | 1703 return; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); | 1778 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); |
| 1780 EXPECT_EQ(2u, num_running_dispatcher_jobs()); | 1779 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
| 1781 requests_[0]->Cancel(); | 1780 requests_[0]->Cancel(); |
| 1782 | 1781 |
| 1783 // Dispatcher state checked in TearDown. | 1782 // Dispatcher state checked in TearDown. |
| 1784 } | 1783 } |
| 1785 | 1784 |
| 1786 // Delete a resolver with some active requests and some queued requests. | 1785 // Delete a resolver with some active requests and some queued requests. |
| 1787 TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) { | 1786 TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) { |
| 1788 // At most 10 Jobs active at once. | 1787 // At most 10 Jobs active at once. |
| 1789 CreateResolverWithLimitsAndParams( | 1788 CreateResolverWithLimitsAndParams(10u, DefaultParams(proc_.get())); |
| 1790 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 10u), | |
| 1791 DefaultParams(proc_.get())); | |
| 1792 | 1789 |
| 1793 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); | 1790 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1794 ChangeDnsConfig(CreateValidDnsConfig()); | 1791 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1795 | 1792 |
| 1796 // First active job is an IPv4 request. | 1793 // First active job is an IPv4 request. |
| 1797 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, | 1794 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, |
| 1798 ADDRESS_FAMILY_IPV4)->Resolve()); | 1795 ADDRESS_FAMILY_IPV4)->Resolve()); |
| 1799 | 1796 |
| 1800 // Add 10 more DNS lookups for different hostnames. First 4 should have two | 1797 // Add 10 more DNS lookups for different hostnames. First 4 should have two |
| 1801 // active jobs, next one has a single active job, and one pending. Others | 1798 // active jobs, next one has a single active job, and one pending. Others |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 EXPECT_TRUE(requests_[0]->completed()); | 1889 EXPECT_TRUE(requests_[0]->completed()); |
| 1893 EXPECT_EQ(OK, requests_[0]->result()); | 1890 EXPECT_EQ(OK, requests_[0]->result()); |
| 1894 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); | 1891 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); |
| 1895 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); | 1892 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); |
| 1896 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); | 1893 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); |
| 1897 } | 1894 } |
| 1898 | 1895 |
| 1899 // Test the case where the AAAA query is started when another transaction | 1896 // Test the case where the AAAA query is started when another transaction |
| 1900 // completes. | 1897 // completes. |
| 1901 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) { | 1898 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) { |
| 1902 CreateResolverWithLimitsAndParams( | 1899 CreateResolverWithLimitsAndParams(2u, DefaultParams(proc_.get())); |
| 1903 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 2), | |
| 1904 DefaultParams(proc_.get())); | |
| 1905 set_fallback_to_proctask(false); | 1900 set_fallback_to_proctask(false); |
| 1906 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); | 1901 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1907 ChangeDnsConfig(CreateValidDnsConfig()); | 1902 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1908 | 1903 |
| 1909 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, | 1904 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, |
| 1910 ADDRESS_FAMILY_IPV4)->Resolve()); | 1905 ADDRESS_FAMILY_IPV4)->Resolve()); |
| 1911 EXPECT_EQ(ERR_IO_PENDING, | 1906 EXPECT_EQ(ERR_IO_PENDING, |
| 1912 CreateRequest("4slow_ok", 80, MEDIUM)->Resolve()); | 1907 CreateRequest("4slow_ok", 80, MEDIUM)->Resolve()); |
| 1913 // An IPv4 request should have been started pending for each job. | 1908 // An IPv4 request should have been started pending for each job. |
| 1914 EXPECT_EQ(2u, num_running_dispatcher_jobs()); | 1909 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 1948 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
| 1954 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 1949 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
| 1955 } | 1950 } |
| 1956 | 1951 |
| 1957 // Tests getting a new invalid DnsConfig while there are active DnsTasks. | 1952 // Tests getting a new invalid DnsConfig while there are active DnsTasks. |
| 1958 TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) { | 1953 TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) { |
| 1959 // At most 3 jobs active at once. This number is important, since we want to | 1954 // At most 3 jobs active at once. This number is important, since we want to |
| 1960 // make sure that aborting the first HostResolverImpl::Job does not trigger | 1955 // make sure that aborting the first HostResolverImpl::Job does not trigger |
| 1961 // another DnsTransaction on the second Job when it releases its second | 1956 // another DnsTransaction on the second Job when it releases its second |
| 1962 // prioritized dispatcher slot. | 1957 // prioritized dispatcher slot. |
| 1963 CreateResolverWithLimitsAndParams( | 1958 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); |
| 1964 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 3u), | |
| 1965 DefaultParams(proc_.get())); | |
| 1966 | 1959 |
| 1967 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); | 1960 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1968 ChangeDnsConfig(CreateValidDnsConfig()); | 1961 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1969 | 1962 |
| 1970 proc_->AddRuleForAllFamilies("slow_nx1", "192.168.0.1"); | 1963 proc_->AddRuleForAllFamilies("slow_nx1", "192.168.0.1"); |
| 1971 proc_->AddRuleForAllFamilies("slow_nx2", "192.168.0.2"); | 1964 proc_->AddRuleForAllFamilies("slow_nx2", "192.168.0.2"); |
| 1972 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); | 1965 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); |
| 1973 | 1966 |
| 1974 // First active job gets two slots. | 1967 // First active job gets two slots. |
| 1975 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx1")->Resolve()); | 1968 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx1")->Resolve()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1996 // Tests the case that DnsClient is automatically disabled due to failures | 1989 // Tests the case that DnsClient is automatically disabled due to failures |
| 1997 // while there are active DnsTasks. | 1990 // while there are active DnsTasks. |
| 1998 TEST_F(HostResolverImplDnsTest, | 1991 TEST_F(HostResolverImplDnsTest, |
| 1999 AutomaticallyDisableDnsClientWithPendingRequests) { | 1992 AutomaticallyDisableDnsClientWithPendingRequests) { |
| 2000 // Trying different limits is important for this test: Different limits | 1993 // Trying different limits is important for this test: Different limits |
| 2001 // result in different behavior when aborting in-progress DnsTasks. Having | 1994 // result in different behavior when aborting in-progress DnsTasks. Having |
| 2002 // a DnsTask that has one job active and one in the queue when another job | 1995 // a DnsTask that has one job active and one in the queue when another job |
| 2003 // occupying two slots has its DnsTask aborted is the case most likely to run | 1996 // occupying two slots has its DnsTask aborted is the case most likely to run |
| 2004 // into problems. | 1997 // into problems. |
| 2005 for (size_t limit = 1u; limit < 6u; ++limit) { | 1998 for (size_t limit = 1u; limit < 6u; ++limit) { |
| 2006 CreateResolverWithLimitsAndParams( | 1999 CreateResolverWithLimitsAndParams(limit, DefaultParams(proc_.get())); |
| 2007 PrioritizedDispatcher::Limits(NUM_PRIORITIES, limit), | |
| 2008 DefaultParams(proc_.get())); | |
| 2009 | 2000 |
| 2010 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); | 2001 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 2011 ChangeDnsConfig(CreateValidDnsConfig()); | 2002 ChangeDnsConfig(CreateValidDnsConfig()); |
| 2012 | 2003 |
| 2013 // Queue up enough failures to disable DnsTasks. These will all fall back | 2004 // Queue up enough failures to disable DnsTasks. These will all fall back |
| 2014 // to ProcTasks, and succeed there. | 2005 // to ProcTasks, and succeed there. |
| 2015 for (unsigned i = 0u; i < maximum_dns_failures(); ++i) { | 2006 for (unsigned i = 0u; i < maximum_dns_failures(); ++i) { |
| 2016 std::string host = base::StringPrintf("nx%u", i); | 2007 std::string host = base::StringPrintf("nx%u", i); |
| 2017 proc_->AddRuleForAllFamilies(host, "192.168.0.1"); | 2008 proc_->AddRuleForAllFamilies(host, "192.168.0.1"); |
| 2018 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(host)->Resolve()); | 2009 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(host)->Resolve()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2045 requests_.clear(); | 2036 requests_.clear(); |
| 2046 } | 2037 } |
| 2047 } | 2038 } |
| 2048 | 2039 |
| 2049 // Tests a call to SetDnsClient while there are active DnsTasks. | 2040 // Tests a call to SetDnsClient while there are active DnsTasks. |
| 2050 TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) { | 2041 TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) { |
| 2051 // At most 3 jobs active at once. This number is important, since we want to | 2042 // At most 3 jobs active at once. This number is important, since we want to |
| 2052 // make sure that aborting the first HostResolverImpl::Job does not trigger | 2043 // make sure that aborting the first HostResolverImpl::Job does not trigger |
| 2053 // another DnsTransaction on the second Job when it releases its second | 2044 // another DnsTransaction on the second Job when it releases its second |
| 2054 // prioritized dispatcher slot. | 2045 // prioritized dispatcher slot. |
| 2055 CreateResolverWithLimitsAndParams( | 2046 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); |
| 2056 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 3u), | |
| 2057 DefaultParams(proc_.get())); | |
| 2058 | 2047 |
| 2059 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); | 2048 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 2060 ChangeDnsConfig(CreateValidDnsConfig()); | 2049 ChangeDnsConfig(CreateValidDnsConfig()); |
| 2061 | 2050 |
| 2062 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.1"); | 2051 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.1"); |
| 2063 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.2"); | 2052 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.2"); |
| 2064 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); | 2053 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); |
| 2065 | 2054 |
| 2066 // First active job gets two slots. | 2055 // First active job gets two slots. |
| 2067 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve()); | 2056 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2082 | 2071 |
| 2083 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 2072 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
| 2084 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 2073 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
| 2085 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 2074 EXPECT_EQ(OK, requests_[1]->WaitForResult()); |
| 2086 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); | 2075 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); |
| 2087 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 2076 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
| 2088 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); | 2077 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
| 2089 } | 2078 } |
| 2090 | 2079 |
| 2091 } // namespace net | 2080 } // namespace net |
| OLD | NEW |