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/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/synchronization/condition_variable.h" | 18 #include "base/synchronization/condition_variable.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "base/test/test_timeouts.h" | 20 #include "base/test/test_timeouts.h" |
20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
21 #include "net/base/address_list.h" | 22 #include "net/base/address_list.h" |
22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
23 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
24 #include "net/dns/dns_client.h" | 25 #include "net/dns/dns_client.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 }; | 414 }; |
414 | 415 |
415 } // namespace | 416 } // namespace |
416 | 417 |
417 class HostResolverImplTest : public testing::Test { | 418 class HostResolverImplTest : public testing::Test { |
418 public: | 419 public: |
419 static const int kDefaultPort = 80; | 420 static const int kDefaultPort = 80; |
420 | 421 |
421 HostResolverImplTest() : proc_(new MockHostResolverProc()) {} | 422 HostResolverImplTest() : proc_(new MockHostResolverProc()) {} |
422 | 423 |
| 424 void CreateResolver() { |
| 425 CreateResolverWithLimitsAndParams(DefaultLimits(), |
| 426 DefaultParams(proc_.get())); |
| 427 } |
| 428 |
| 429 // This HostResolverImpl will only allow 1 outstanding resolve at a time and |
| 430 // perform no retries. |
| 431 void CreateSerialResolver() { |
| 432 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get()); |
| 433 params.max_retry_attempts = 0u; |
| 434 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); |
| 435 CreateResolverWithLimitsAndParams(limits, params); |
| 436 } |
| 437 |
423 protected: | 438 protected: |
424 // A Request::Handler which is a proxy to the HostResolverImplTest fixture. | 439 // A Request::Handler which is a proxy to the HostResolverImplTest fixture. |
425 struct Handler : public Request::Handler { | 440 struct Handler : public Request::Handler { |
426 virtual ~Handler() {} | 441 virtual ~Handler() {} |
427 | 442 |
428 // Proxy functions so that classes derived from Handler can access them. | 443 // Proxy functions so that classes derived from Handler can access them. |
429 Request* CreateRequest(const HostResolver::RequestInfo& info, | 444 Request* CreateRequest(const HostResolver::RequestInfo& info, |
430 RequestPriority priority) { | 445 RequestPriority priority) { |
431 return test->CreateRequest(info, priority); | 446 return test->CreateRequest(info, priority); |
432 } | 447 } |
433 Request* CreateRequest(const std::string& hostname, int port) { | 448 Request* CreateRequest(const std::string& hostname, int port) { |
434 return test->CreateRequest(hostname, port); | 449 return test->CreateRequest(hostname, port); |
435 } | 450 } |
436 Request* CreateRequest(const std::string& hostname) { | 451 Request* CreateRequest(const std::string& hostname) { |
437 return test->CreateRequest(hostname); | 452 return test->CreateRequest(hostname); |
438 } | 453 } |
439 ScopedVector<Request>& requests() { return test->requests_; } | 454 ScopedVector<Request>& requests() { return test->requests_; } |
440 | 455 |
441 void DeleteResolver() { test->resolver_.reset(); } | 456 void DeleteResolver() { test->resolver_.reset(); } |
442 | 457 |
443 HostResolverImplTest* test; | 458 HostResolverImplTest* test; |
444 }; | 459 }; |
445 | 460 |
446 void CreateResolver() { | 461 // testing::Test implementation: |
447 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), | 462 virtual void SetUp() OVERRIDE { |
448 DefaultLimits(), | 463 CreateResolver(); |
449 DefaultParams(proc_.get()), | |
450 NULL)); | |
451 } | 464 } |
452 | 465 |
453 // This HostResolverImpl will only allow 1 outstanding resolve at a time and | 466 virtual void TearDown() OVERRIDE { |
454 // perform no retries. | 467 if (resolver_.get()) |
455 void CreateSerialResolver() { | 468 EXPECT_EQ(0u, resolver_->num_running_dispatcher_jobs_for_tests()); |
456 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get()); | 469 EXPECT_FALSE(proc_->HasBlockedRequests()); |
457 params.max_retry_attempts = 0u; | 470 } |
458 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); | 471 |
459 resolver_.reset(new HostResolverImpl( | 472 virtual void CreateResolverWithLimitsAndParams( |
460 HostCache::CreateDefaultCache(), | 473 const PrioritizedDispatcher::Limits& limits, |
461 limits, | 474 const HostResolverImpl::ProcTaskParams& params) { |
462 params, | 475 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), |
463 NULL)); | 476 limits, params, NULL)); |
464 } | 477 } |
465 | 478 |
466 // The Request will not be made until a call to |Resolve()|, and the Job will | 479 // The Request will not be made until a call to |Resolve()|, and the Job will |
467 // not start until released by |proc_->SignalXXX|. | 480 // not start until released by |proc_->SignalXXX|. |
468 Request* CreateRequest(const HostResolver::RequestInfo& info, | 481 Request* CreateRequest(const HostResolver::RequestInfo& info, |
469 RequestPriority priority) { | 482 RequestPriority priority) { |
470 Request* req = new Request( | 483 Request* req = new Request( |
471 info, priority, requests_.size(), resolver_.get(), handler_.get()); | 484 info, priority, requests_.size(), resolver_.get(), handler_.get()); |
472 requests_.push_back(req); | 485 requests_.push_back(req); |
473 return req; | 486 return req; |
(...skipping 15 matching lines...) Expand all Loading... |
489 } | 502 } |
490 | 503 |
491 Request* CreateRequest(const std::string& hostname, int port) { | 504 Request* CreateRequest(const std::string& hostname, int port) { |
492 return CreateRequest(hostname, port, MEDIUM); | 505 return CreateRequest(hostname, port, MEDIUM); |
493 } | 506 } |
494 | 507 |
495 Request* CreateRequest(const std::string& hostname) { | 508 Request* CreateRequest(const std::string& hostname) { |
496 return CreateRequest(hostname, kDefaultPort); | 509 return CreateRequest(hostname, kDefaultPort); |
497 } | 510 } |
498 | 511 |
499 virtual void SetUp() OVERRIDE { | |
500 CreateResolver(); | |
501 } | |
502 | |
503 virtual void TearDown() OVERRIDE { | |
504 if (resolver_.get()) | |
505 EXPECT_EQ(0u, resolver_->num_running_jobs_for_tests()); | |
506 EXPECT_FALSE(proc_->HasBlockedRequests()); | |
507 } | |
508 | |
509 void set_handler(Handler* handler) { | 512 void set_handler(Handler* handler) { |
510 handler_.reset(handler); | 513 handler_.reset(handler); |
511 handler_->test = this; | 514 handler_->test = this; |
512 } | 515 } |
513 | 516 |
514 // Friendship is not inherited, so use proxies to access those. | 517 // Friendship is not inherited, so use proxies to access those. |
515 size_t num_running_jobs() const { | 518 size_t num_running_dispatcher_jobs() const { |
516 DCHECK(resolver_.get()); | 519 DCHECK(resolver_.get()); |
517 return resolver_->num_running_jobs_for_tests(); | 520 return resolver_->num_running_dispatcher_jobs_for_tests(); |
518 } | 521 } |
519 | 522 |
520 void set_fallback_to_proctask(bool fallback_to_proctask) { | 523 void set_fallback_to_proctask(bool fallback_to_proctask) { |
521 DCHECK(resolver_.get()); | 524 DCHECK(resolver_.get()); |
522 resolver_->fallback_to_proctask_ = fallback_to_proctask; | 525 resolver_->fallback_to_proctask_ = fallback_to_proctask; |
523 } | 526 } |
524 | 527 |
| 528 static unsigned maximum_dns_failures() { |
| 529 return HostResolverImpl::kMaximumDnsFailures; |
| 530 } |
| 531 |
525 scoped_refptr<MockHostResolverProc> proc_; | 532 scoped_refptr<MockHostResolverProc> proc_; |
526 scoped_ptr<HostResolverImpl> resolver_; | 533 scoped_ptr<HostResolverImpl> resolver_; |
527 ScopedVector<Request> requests_; | 534 ScopedVector<Request> requests_; |
528 | 535 |
529 scoped_ptr<Handler> handler_; | 536 scoped_ptr<Handler> handler_; |
530 }; | 537 }; |
531 | 538 |
532 TEST_F(HostResolverImplTest, AsynchronousLookup) { | 539 TEST_F(HostResolverImplTest, AsynchronousLookup) { |
533 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); | 540 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); |
534 proc_->SignalMultiple(1u); | 541 proc_->SignalMultiple(1u); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); | 898 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); |
892 | 899 |
893 EXPECT_TRUE(proc_->WaitFor(1u)); | 900 EXPECT_TRUE(proc_->WaitFor(1u)); |
894 // Triggering an IP address change. | 901 // Triggering an IP address change. |
895 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 902 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
896 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 903 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
897 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. | 904 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. |
898 | 905 |
899 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); | 906 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); |
900 | 907 |
901 EXPECT_EQ(1u, num_running_jobs()); | 908 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
902 | 909 |
903 EXPECT_FALSE(requests_[1]->completed()); | 910 EXPECT_FALSE(requests_[1]->completed()); |
904 EXPECT_FALSE(requests_[2]->completed()); | 911 EXPECT_FALSE(requests_[2]->completed()); |
905 | 912 |
906 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 913 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
907 EXPECT_EQ(OK, requests_[1]->result()); | 914 EXPECT_EQ(OK, requests_[1]->result()); |
908 } | 915 } |
909 | 916 |
910 // Tests that a new Request made from the callback of a previously aborted one | 917 // Tests that a new Request made from the callback of a previously aborted one |
911 // will not be aborted. | 918 // will not be aborted. |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 EXPECT_TRUE(rv); | 1265 EXPECT_TRUE(rv); |
1259 | 1266 |
1260 DnsConfig config; | 1267 DnsConfig config; |
1261 config.nameservers.push_back(IPEndPoint(dns_ip, dns_protocol::kDefaultPort)); | 1268 config.nameservers.push_back(IPEndPoint(dns_ip, dns_protocol::kDefaultPort)); |
1262 EXPECT_TRUE(config.IsValid()); | 1269 EXPECT_TRUE(config.IsValid()); |
1263 return config; | 1270 return config; |
1264 } | 1271 } |
1265 | 1272 |
1266 // Specialized fixture for tests of DnsTask. | 1273 // Specialized fixture for tests of DnsTask. |
1267 class HostResolverImplDnsTest : public HostResolverImplTest { | 1274 class HostResolverImplDnsTest : public HostResolverImplTest { |
| 1275 public: |
| 1276 HostResolverImplDnsTest() : dns_client_(NULL) {} |
| 1277 |
1268 protected: | 1278 protected: |
| 1279 // testing::Test implementation: |
1269 virtual void SetUp() OVERRIDE { | 1280 virtual void SetUp() OVERRIDE { |
1270 AddDnsRule("nx", dns_protocol::kTypeA, MockDnsClientRule::FAIL); | 1281 AddDnsRule("nx", dns_protocol::kTypeA, MockDnsClientRule::FAIL, false); |
1271 AddDnsRule("nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL); | 1282 AddDnsRule("nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL, false); |
1272 AddDnsRule("ok", dns_protocol::kTypeA, MockDnsClientRule::OK); | 1283 AddDnsRule("ok", dns_protocol::kTypeA, MockDnsClientRule::OK, false); |
1273 AddDnsRule("ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK); | 1284 AddDnsRule("ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, false); |
1274 AddDnsRule("4ok", dns_protocol::kTypeA, MockDnsClientRule::OK); | 1285 AddDnsRule("4ok", dns_protocol::kTypeA, MockDnsClientRule::OK, false); |
1275 AddDnsRule("4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY); | 1286 AddDnsRule("4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY, false); |
1276 AddDnsRule("6ok", dns_protocol::kTypeA, MockDnsClientRule::EMPTY); | 1287 AddDnsRule("6ok", dns_protocol::kTypeA, MockDnsClientRule::EMPTY, false); |
1277 AddDnsRule("6ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK); | 1288 AddDnsRule("6ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, false); |
1278 AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK); | 1289 AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK, false); |
1279 AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL); | 1290 AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL, false); |
| 1291 AddDnsRule("empty", dns_protocol::kTypeA, MockDnsClientRule::EMPTY, false); |
| 1292 AddDnsRule("empty", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY, |
| 1293 false); |
| 1294 |
| 1295 AddDnsRule("slow_nx", dns_protocol::kTypeA, MockDnsClientRule::FAIL, true); |
| 1296 AddDnsRule("slow_nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL, |
| 1297 true); |
| 1298 |
| 1299 AddDnsRule("4slow_ok", dns_protocol::kTypeA, MockDnsClientRule::OK, true); |
| 1300 AddDnsRule("4slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, |
| 1301 false); |
| 1302 AddDnsRule("6slow_ok", dns_protocol::kTypeA, MockDnsClientRule::OK, false); |
| 1303 AddDnsRule("6slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, |
| 1304 true); |
| 1305 AddDnsRule("4slow_4ok", dns_protocol::kTypeA, MockDnsClientRule::OK, true); |
| 1306 AddDnsRule("4slow_4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY, |
| 1307 false); |
| 1308 AddDnsRule("4slow_4timeout", dns_protocol::kTypeA, |
| 1309 MockDnsClientRule::TIMEOUT, true); |
| 1310 AddDnsRule("4slow_4timeout", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, |
| 1311 false); |
| 1312 AddDnsRule("4slow_6timeout", dns_protocol::kTypeA, |
| 1313 MockDnsClientRule::OK, true); |
| 1314 AddDnsRule("4slow_6timeout", dns_protocol::kTypeAAAA, |
| 1315 MockDnsClientRule::TIMEOUT, false); |
1280 CreateResolver(); | 1316 CreateResolver(); |
1281 } | 1317 } |
1282 | 1318 |
1283 void CreateResolver() { | 1319 // HostResolverImplTest implementation: |
| 1320 virtual void CreateResolverWithLimitsAndParams( |
| 1321 const PrioritizedDispatcher::Limits& limits, |
| 1322 const HostResolverImpl::ProcTaskParams& params) OVERRIDE { |
1284 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), | 1323 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), |
1285 DefaultLimits(), | 1324 limits, |
1286 DefaultParams(proc_.get()), | 1325 params, |
1287 NULL)); | 1326 NULL)); |
1288 // Disable IPv6 support probing. | 1327 // Disable IPv6 support probing. |
1289 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); | 1328 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
1290 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); | 1329 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_); |
| 1330 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_)); |
1291 } | 1331 } |
1292 | 1332 |
1293 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. | 1333 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. |
1294 void AddDnsRule(const std::string& prefix, | 1334 void AddDnsRule(const std::string& prefix, |
1295 uint16 qtype, | 1335 uint16 qtype, |
1296 MockDnsClientRule::Result result) { | 1336 MockDnsClientRule::Result result, |
1297 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result)); | 1337 bool delay) { |
| 1338 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay)); |
1298 } | 1339 } |
1299 | 1340 |
1300 void ChangeDnsConfig(const DnsConfig& config) { | 1341 void ChangeDnsConfig(const DnsConfig& config) { |
1301 NetworkChangeNotifier::SetDnsConfig(config); | 1342 NetworkChangeNotifier::SetDnsConfig(config); |
1302 // Notification is delivered asynchronously. | 1343 // Notification is delivered asynchronously. |
1303 base::MessageLoop::current()->RunUntilIdle(); | 1344 base::MessageLoop::current()->RunUntilIdle(); |
1304 } | 1345 } |
1305 | 1346 |
1306 MockDnsClientRuleList dns_rules_; | 1347 MockDnsClientRuleList dns_rules_; |
| 1348 // Owned by |resolver_|. |
| 1349 MockDnsClient* dns_client_; |
1307 }; | 1350 }; |
1308 | 1351 |
1309 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. | 1352 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. |
1310 | 1353 |
1311 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1354 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
1312 | 1355 |
1313 // Test successful and fallback resolutions in HostResolverImpl::DnsTask. | 1356 // Test successful and fallback resolutions in HostResolverImpl::DnsTask. |
1314 TEST_F(HostResolverImplDnsTest, DnsTask) { | 1357 TEST_F(HostResolverImplDnsTest, DnsTask) { |
1315 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1358 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
1316 | 1359 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 1407 EXPECT_EQ(OK, requests_[1]->WaitForResult()); |
1365 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80)); | 1408 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80)); |
1366 | 1409 |
1367 ChangeDnsConfig(CreateValidDnsConfig()); | 1410 ChangeDnsConfig(CreateValidDnsConfig()); |
1368 | 1411 |
1369 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80)->Resolve()); | 1412 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80)->Resolve()); |
1370 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); | 1413 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); |
1371 | 1414 |
1372 // Simulate the case when the preference or policy has disabled the DNS client | 1415 // Simulate the case when the preference or policy has disabled the DNS client |
1373 // causing AbortDnsTasks. | 1416 // causing AbortDnsTasks. |
1374 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); | 1417 resolver_->SetDnsClient( |
| 1418 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); |
1375 ChangeDnsConfig(CreateValidDnsConfig()); | 1419 ChangeDnsConfig(CreateValidDnsConfig()); |
1376 | 1420 |
1377 // First request is resolved by MockDnsClient, others should fail due to | 1421 // First request is resolved by MockDnsClient, others should fail due to |
1378 // disabled fallback to ProcTask. | 1422 // disabled fallback to ProcTask. |
1379 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); | 1423 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); |
1380 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80)->Resolve()); | 1424 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80)->Resolve()); |
1381 proc_->SignalMultiple(requests_.size()); | 1425 proc_->SignalMultiple(requests_.size()); |
1382 | 1426 |
1383 // Aborted due to Network Change. | 1427 // Aborted due to Network Change. |
1384 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->WaitForResult()); | 1428 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->WaitForResult()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 ChangeDnsConfig(CreateValidDnsConfig()); | 1567 ChangeDnsConfig(CreateValidDnsConfig()); |
1524 | 1568 |
1525 proc_->AddRuleForAllFamilies(std::string(), | 1569 proc_->AddRuleForAllFamilies(std::string(), |
1526 std::string()); // Default to failures. | 1570 std::string()); // Default to failures. |
1527 | 1571 |
1528 // Check that DnsTask works. | 1572 // Check that DnsTask works. |
1529 Request* req = CreateRequest("ok_1", 80); | 1573 Request* req = CreateRequest("ok_1", 80); |
1530 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1574 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
1531 EXPECT_EQ(OK, req->WaitForResult()); | 1575 EXPECT_EQ(OK, req->WaitForResult()); |
1532 | 1576 |
1533 for (unsigned i = 0; i < 20; ++i) { | 1577 for (unsigned i = 0; i < maximum_dns_failures(); ++i) { |
1534 // Use custom names to require separate Jobs. | 1578 // Use custom names to require separate Jobs. |
1535 std::string hostname = base::StringPrintf("nx_%u", i); | 1579 std::string hostname = base::StringPrintf("nx_%u", i); |
1536 // Ensure fallback to ProcTask succeeds. | 1580 // Ensure fallback to ProcTask succeeds. |
1537 proc_->AddRuleForAllFamilies(hostname, "192.168.1.101"); | 1581 proc_->AddRuleForAllFamilies(hostname, "192.168.1.101"); |
1538 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 80)->Resolve()) << i; | 1582 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 80)->Resolve()) << i; |
1539 } | 1583 } |
1540 | 1584 |
1541 proc_->SignalMultiple(requests_.size()); | 1585 proc_->SignalMultiple(requests_.size()); |
1542 | 1586 |
1543 for (size_t i = 0; i < requests_.size(); ++i) | 1587 for (size_t i = 0; i < requests_.size(); ++i) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 // Confirm that resolving "localhost" is unrestricted even if there are no | 1632 // Confirm that resolving "localhost" is unrestricted even if there are no |
1589 // global IPv6 address. See SystemHostResolverCall for rationale. | 1633 // global IPv6 address. See SystemHostResolverCall for rationale. |
1590 // Test both the DnsClient and system host resolver paths. | 1634 // Test both the DnsClient and system host resolver paths. |
1591 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { | 1635 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { |
1592 // Use regular SystemHostResolverCall! | 1636 // Use regular SystemHostResolverCall! |
1593 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); | 1637 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); |
1594 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), | 1638 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), |
1595 DefaultLimits(), | 1639 DefaultLimits(), |
1596 DefaultParams(proc.get()), | 1640 DefaultParams(proc.get()), |
1597 NULL)); | 1641 NULL)); |
1598 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); | 1642 resolver_->SetDnsClient( |
| 1643 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); |
1599 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1644 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
1600 | 1645 |
1601 // Get the expected output. | 1646 // Get the expected output. |
1602 AddressList addrlist; | 1647 AddressList addrlist; |
1603 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, | 1648 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, |
1604 NULL); | 1649 NULL); |
1605 if (rv != OK) | 1650 if (rv != OK) |
1606 return; | 1651 return; |
1607 | 1652 |
1608 for (unsigned i = 0; i < addrlist.size(); ++i) | 1653 for (unsigned i = 0; i < addrlist.size(); ++i) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 | 1686 |
1642 ChangeDnsConfig(config); | 1687 ChangeDnsConfig(config); |
1643 req = CreateRequest(info, DEFAULT_PRIORITY); | 1688 req = CreateRequest(info, DEFAULT_PRIORITY); |
1644 // Expect synchronous resolution from DnsHosts. | 1689 // Expect synchronous resolution from DnsHosts. |
1645 EXPECT_EQ(OK, req->Resolve()); | 1690 EXPECT_EQ(OK, req->Resolve()); |
1646 | 1691 |
1647 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); | 1692 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); |
1648 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); | 1693 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); |
1649 } | 1694 } |
1650 | 1695 |
| 1696 // Cancel a request with a single DNS transaction active. |
| 1697 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActive) { |
| 1698 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1699 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1700 |
| 1701 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); |
| 1702 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
| 1703 requests_[0]->Cancel(); |
| 1704 |
| 1705 // Dispatcher state checked in TearDown. |
| 1706 } |
| 1707 |
| 1708 // Cancel a request with a single DNS transaction active and another pending. |
| 1709 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActiveOnePending) { |
| 1710 CreateSerialResolver(); |
| 1711 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1712 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1713 |
| 1714 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); |
| 1715 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
| 1716 requests_[0]->Cancel(); |
| 1717 |
| 1718 // Dispatcher state checked in TearDown. |
| 1719 } |
| 1720 |
| 1721 // Cancel a request with two DNS transactions active. |
| 1722 TEST_F(HostResolverImplDnsTest, CancelWithTwoTransactionsActive) { |
| 1723 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1724 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1725 |
| 1726 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); |
| 1727 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
| 1728 requests_[0]->Cancel(); |
| 1729 |
| 1730 // Dispatcher state checked in TearDown. |
| 1731 } |
| 1732 |
| 1733 // Delete a resolver with some active requests and some queued requests. |
| 1734 TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) { |
| 1735 // At most 10 Jobs active at once. |
| 1736 CreateResolverWithLimitsAndParams( |
| 1737 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 10u), |
| 1738 DefaultParams(proc_.get())); |
| 1739 |
| 1740 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1741 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1742 |
| 1743 // First active job is an IPv4 request. |
| 1744 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, |
| 1745 ADDRESS_FAMILY_IPV4)->Resolve()); |
| 1746 |
| 1747 // Add 10 more DNS lookups for different hostnames. First 4 should have two |
| 1748 // active jobs, next one has a single active job, and one pending. Others |
| 1749 // should all be queued. |
| 1750 for (int i = 0; i < 10; ++i) { |
| 1751 EXPECT_EQ(ERR_IO_PENDING, CreateRequest( |
| 1752 base::StringPrintf("ok%i", i))->Resolve()); |
| 1753 } |
| 1754 EXPECT_EQ(10u, num_running_dispatcher_jobs()); |
| 1755 |
| 1756 resolver_.reset(); |
| 1757 } |
| 1758 |
| 1759 // Cancel a request with only the IPv6 transaction active. |
| 1760 TEST_F(HostResolverImplDnsTest, CancelWithIPv6TransactionActive) { |
| 1761 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1762 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1763 |
| 1764 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("6slow_ok", 80)->Resolve()); |
| 1765 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
| 1766 |
| 1767 // The IPv4 request should complete, the IPv6 request is still pending. |
| 1768 base::RunLoop().RunUntilIdle(); |
| 1769 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
| 1770 requests_[0]->Cancel(); |
| 1771 |
| 1772 // Dispatcher state checked in TearDown. |
| 1773 } |
| 1774 |
| 1775 // Cancel a request with only the IPv4 transaction pending. |
| 1776 TEST_F(HostResolverImplDnsTest, CancelWithIPv4TransactionPending) { |
| 1777 set_fallback_to_proctask(false); |
| 1778 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1779 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1780 |
| 1781 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve()); |
| 1782 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
| 1783 |
| 1784 // The IPv6 request should complete, the IPv4 request is still pending. |
| 1785 base::RunLoop().RunUntilIdle(); |
| 1786 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
| 1787 |
| 1788 requests_[0]->Cancel(); |
| 1789 } |
| 1790 |
| 1791 // Test cases where AAAA completes first. |
| 1792 TEST_F(HostResolverImplDnsTest, AAAACompletesFirst) { |
| 1793 set_fallback_to_proctask(false); |
| 1794 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1795 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1796 |
| 1797 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve()); |
| 1798 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4ok", 80)->Resolve()); |
| 1799 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4timeout", 80)->Resolve()); |
| 1800 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_6timeout", 80)->Resolve()); |
| 1801 |
| 1802 base::RunLoop().RunUntilIdle(); |
| 1803 EXPECT_FALSE(requests_[0]->completed()); |
| 1804 EXPECT_FALSE(requests_[1]->completed()); |
| 1805 EXPECT_FALSE(requests_[2]->completed()); |
| 1806 // The IPv6 of the third request should have failed and resulted in cancelling |
| 1807 // the IPv4 request. |
| 1808 EXPECT_TRUE(requests_[3]->completed()); |
| 1809 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[3]->result()); |
| 1810 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
| 1811 |
| 1812 dns_client_->CompleteDelayedTransactions(); |
| 1813 EXPECT_TRUE(requests_[0]->completed()); |
| 1814 EXPECT_EQ(OK, requests_[0]->result()); |
| 1815 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); |
| 1816 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); |
| 1817 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); |
| 1818 |
| 1819 EXPECT_TRUE(requests_[1]->completed()); |
| 1820 EXPECT_EQ(OK, requests_[1]->result()); |
| 1821 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses()); |
| 1822 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); |
| 1823 |
| 1824 EXPECT_TRUE(requests_[2]->completed()); |
| 1825 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[2]->result()); |
| 1826 } |
| 1827 |
| 1828 // Test the case where only a single transaction slot is available. |
| 1829 TEST_F(HostResolverImplDnsTest, SerialResolver) { |
| 1830 CreateSerialResolver(); |
| 1831 set_fallback_to_proctask(false); |
| 1832 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1833 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1834 |
| 1835 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); |
| 1836 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
| 1837 |
| 1838 base::RunLoop().RunUntilIdle(); |
| 1839 EXPECT_TRUE(requests_[0]->completed()); |
| 1840 EXPECT_EQ(OK, requests_[0]->result()); |
| 1841 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); |
| 1842 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); |
| 1843 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); |
| 1844 } |
| 1845 |
| 1846 // Test the case where the AAAA query is started when another transaction |
| 1847 // completes. |
| 1848 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) { |
| 1849 CreateResolverWithLimitsAndParams( |
| 1850 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 2), |
| 1851 DefaultParams(proc_.get())); |
| 1852 set_fallback_to_proctask(false); |
| 1853 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1854 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1855 |
| 1856 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, |
| 1857 ADDRESS_FAMILY_IPV4)->Resolve()); |
| 1858 EXPECT_EQ(ERR_IO_PENDING, |
| 1859 CreateRequest("4slow_ok", 80, MEDIUM)->Resolve()); |
| 1860 // An IPv4 request should have been started pending for each job. |
| 1861 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
| 1862 |
| 1863 // Request 0's IPv4 request should complete, starting Request 1's IPv6 |
| 1864 // request, which should also complete. |
| 1865 base::RunLoop().RunUntilIdle(); |
| 1866 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
| 1867 EXPECT_TRUE(requests_[0]->completed()); |
| 1868 EXPECT_FALSE(requests_[1]->completed()); |
| 1869 |
| 1870 dns_client_->CompleteDelayedTransactions(); |
| 1871 EXPECT_TRUE(requests_[1]->completed()); |
| 1872 EXPECT_EQ(OK, requests_[1]->result()); |
| 1873 EXPECT_EQ(2u, requests_[1]->NumberOfAddresses()); |
| 1874 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); |
| 1875 EXPECT_TRUE(requests_[1]->HasAddress("::1", 80)); |
| 1876 } |
| 1877 |
| 1878 // Tests the case that a Job with a single transaction receives an empty address |
| 1879 // list, triggering fallback to ProcTask. |
| 1880 TEST_F(HostResolverImplDnsTest, IPv4EmptyFallback) { |
| 1881 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1882 proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1"); |
| 1883 proc_->SignalMultiple(1u); |
| 1884 EXPECT_EQ(ERR_IO_PENDING, |
| 1885 CreateRequest("empty_fallback", 80, MEDIUM, |
| 1886 ADDRESS_FAMILY_IPV4)->Resolve()); |
| 1887 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
| 1888 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
| 1889 } |
| 1890 |
| 1891 // Tests the case that a Job with two transactions receives two empty address |
| 1892 // lists, triggering fallback to ProcTask. |
| 1893 TEST_F(HostResolverImplDnsTest, UnspecEmptyFallback) { |
| 1894 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1895 proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1"); |
| 1896 proc_->SignalMultiple(1u); |
| 1897 EXPECT_EQ(ERR_IO_PENDING, |
| 1898 CreateRequest("empty_fallback", 80, MEDIUM, |
| 1899 ADDRESS_FAMILY_UNSPECIFIED)->Resolve()); |
| 1900 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
| 1901 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
| 1902 } |
| 1903 |
| 1904 // Tests getting a new invalid DnsConfig while there are active DnsTasks. |
| 1905 TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) { |
| 1906 // At most 3 jobs active at once. This number is important, since we want to |
| 1907 // make sure that aborting the first HostResolverImpl::Job does not trigger |
| 1908 // another DnsTransaction on the second Job when it releases its second |
| 1909 // prioritized dispatcher slot. |
| 1910 CreateResolverWithLimitsAndParams( |
| 1911 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 3u), |
| 1912 DefaultParams(proc_.get())); |
| 1913 |
| 1914 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1915 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1916 |
| 1917 proc_->AddRuleForAllFamilies("slow_nx1", "192.168.0.1"); |
| 1918 proc_->AddRuleForAllFamilies("slow_nx2", "192.168.0.2"); |
| 1919 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); |
| 1920 |
| 1921 // First active job gets two slots. |
| 1922 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx1")->Resolve()); |
| 1923 // Next job gets one slot, and waits on another. |
| 1924 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx2")->Resolve()); |
| 1925 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok")->Resolve()); |
| 1926 |
| 1927 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
| 1928 |
| 1929 // Clear DNS config. Two in-progress jobs should be aborted, and the next one |
| 1930 // should use a ProcTask. |
| 1931 ChangeDnsConfig(DnsConfig()); |
| 1932 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); |
| 1933 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[1]->WaitForResult()); |
| 1934 |
| 1935 // Finish up the third job. Should bypass the DnsClient, and get its results |
| 1936 // from MockHostResolverProc. |
| 1937 EXPECT_FALSE(requests_[2]->completed()); |
| 1938 proc_->SignalMultiple(1u); |
| 1939 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
| 1940 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
| 1941 } |
| 1942 |
| 1943 // Tests the case that DnsClient is automatically disabled due to failures |
| 1944 // while there are active DnsTasks. |
| 1945 TEST_F(HostResolverImplDnsTest, |
| 1946 AutomaticallyDisableDnsClientWithPendingRequests) { |
| 1947 // Trying different limits is important for this test: Different limits |
| 1948 // result in different behavior when aborting in-progress DnsTasks. Having |
| 1949 // a DnsTask that has one job active and one in the queue when another job |
| 1950 // occupying two slots has its DnsTask aborted is the case most likely to run |
| 1951 // into problems. |
| 1952 for (size_t limit = 1u; limit < 6u; ++limit) { |
| 1953 CreateResolverWithLimitsAndParams( |
| 1954 PrioritizedDispatcher::Limits(NUM_PRIORITIES, limit), |
| 1955 DefaultParams(proc_.get())); |
| 1956 |
| 1957 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 1958 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1959 |
| 1960 // Queue up enough failures to disable DnsTasks. These will all fall back |
| 1961 // to ProcTasks, and succeed there. |
| 1962 for (unsigned i = 0u; i < maximum_dns_failures(); ++i) { |
| 1963 std::string host = base::StringPrintf("nx%u", i); |
| 1964 proc_->AddRuleForAllFamilies(host, "192.168.0.1"); |
| 1965 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(host)->Resolve()); |
| 1966 } |
| 1967 |
| 1968 // These requests should all bypass DnsTasks, due to the above failures, |
| 1969 // so should end up using ProcTasks. |
| 1970 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.2"); |
| 1971 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve()); |
| 1972 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.3"); |
| 1973 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok2")->Resolve()); |
| 1974 proc_->AddRuleForAllFamilies("slow_ok3", "192.168.0.4"); |
| 1975 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok3")->Resolve()); |
| 1976 proc_->SignalMultiple(maximum_dns_failures() + 3); |
| 1977 |
| 1978 for (size_t i = 0u; i < maximum_dns_failures(); ++i) { |
| 1979 EXPECT_EQ(OK, requests_[i]->WaitForResult()); |
| 1980 EXPECT_TRUE(requests_[i]->HasOneAddress("192.168.0.1", 80)); |
| 1981 } |
| 1982 |
| 1983 EXPECT_EQ(OK, requests_[maximum_dns_failures()]->WaitForResult()); |
| 1984 EXPECT_TRUE(requests_[maximum_dns_failures()]->HasOneAddress( |
| 1985 "192.168.0.2", 80)); |
| 1986 EXPECT_EQ(OK, requests_[maximum_dns_failures() + 1]->WaitForResult()); |
| 1987 EXPECT_TRUE(requests_[maximum_dns_failures() + 1]->HasOneAddress( |
| 1988 "192.168.0.3", 80)); |
| 1989 EXPECT_EQ(OK, requests_[maximum_dns_failures() + 2]->WaitForResult()); |
| 1990 EXPECT_TRUE(requests_[maximum_dns_failures() + 2]->HasOneAddress( |
| 1991 "192.168.0.4", 80)); |
| 1992 requests_.clear(); |
| 1993 } |
| 1994 } |
| 1995 |
| 1996 // Tests a call to SetDnsClient while there are active DnsTasks. |
| 1997 TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) { |
| 1998 // At most 3 jobs active at once. This number is important, since we want to |
| 1999 // make sure that aborting the first HostResolverImpl::Job does not trigger |
| 2000 // another DnsTransaction on the second Job when it releases its second |
| 2001 // prioritized dispatcher slot. |
| 2002 CreateResolverWithLimitsAndParams( |
| 2003 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 3u), |
| 2004 DefaultParams(proc_.get())); |
| 2005 |
| 2006 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); |
| 2007 ChangeDnsConfig(CreateValidDnsConfig()); |
| 2008 |
| 2009 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.1"); |
| 2010 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.2"); |
| 2011 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); |
| 2012 |
| 2013 // First active job gets two slots. |
| 2014 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve()); |
| 2015 // Next job gets one slot, and waits on another. |
| 2016 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok2")->Resolve()); |
| 2017 // Next one is queued. |
| 2018 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok")->Resolve()); |
| 2019 |
| 2020 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
| 2021 |
| 2022 // Clear DnsClient. The two in-progress jobs should fall back to a ProcTask, |
| 2023 // and the next one should be started with a ProcTask. |
| 2024 resolver_->SetDnsClient(scoped_ptr<DnsClient>()); |
| 2025 |
| 2026 // All three in-progress requests should now be running a ProcTask. |
| 2027 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
| 2028 proc_->SignalMultiple(3u); |
| 2029 |
| 2030 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
| 2031 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
| 2032 EXPECT_EQ(OK, requests_[1]->WaitForResult()); |
| 2033 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); |
| 2034 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
| 2035 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
| 2036 } |
| 2037 |
1651 } // namespace net | 2038 } // namespace net |
OLD | NEW |