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

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

Issue 19498003: [net/dns] Perform A/AAAA queries for AF_UNSPEC resolutions in parallel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add space Created 7 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 unified diff | Download patch | Annotate | Revision Log
« net/dns/host_resolver_impl.cc ('K') | « net/dns/host_resolver_impl.cc ('k') | no next file » | 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/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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 }; 407 };
407 408
408 } // namespace 409 } // namespace
409 410
410 class HostResolverImplTest : public testing::Test { 411 class HostResolverImplTest : public testing::Test {
411 public: 412 public:
412 static const int kDefaultPort = 80; 413 static const int kDefaultPort = 80;
413 414
414 HostResolverImplTest() : proc_(new MockHostResolverProc()) {} 415 HostResolverImplTest() : proc_(new MockHostResolverProc()) {}
415 416
417 void CreateResolver() {
418 CreateResolverWithLimitsAndParams(DefaultLimits(),
419 DefaultParams(proc_.get()));
420 }
421
422 // This HostResolverImpl will only allow 1 outstanding resolve at a time and
423 // perform no retries.
424 void CreateSerialResolver() {
425 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get());
426 params.max_retry_attempts = 0u;
427 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1);
428 CreateResolverWithLimitsAndParams(limits, params);
429 }
430
416 protected: 431 protected:
417 // A Request::Handler which is a proxy to the HostResolverImplTest fixture. 432 // A Request::Handler which is a proxy to the HostResolverImplTest fixture.
418 struct Handler : public Request::Handler { 433 struct Handler : public Request::Handler {
419 virtual ~Handler() {} 434 virtual ~Handler() {}
420 435
421 // Proxy functions so that classes derived from Handler can access them. 436 // Proxy functions so that classes derived from Handler can access them.
422 Request* CreateRequest(const HostResolver::RequestInfo& info) { 437 Request* CreateRequest(const HostResolver::RequestInfo& info) {
423 return test->CreateRequest(info); 438 return test->CreateRequest(info);
424 } 439 }
425 Request* CreateRequest(const std::string& hostname, int port) { 440 Request* CreateRequest(const std::string& hostname, int port) {
426 return test->CreateRequest(hostname, port); 441 return test->CreateRequest(hostname, port);
427 } 442 }
428 Request* CreateRequest(const std::string& hostname) { 443 Request* CreateRequest(const std::string& hostname) {
429 return test->CreateRequest(hostname); 444 return test->CreateRequest(hostname);
430 } 445 }
431 ScopedVector<Request>& requests() { return test->requests_; } 446 ScopedVector<Request>& requests() { return test->requests_; }
432 447
433 void DeleteResolver() { test->resolver_.reset(); } 448 void DeleteResolver() { test->resolver_.reset(); }
434 449
435 HostResolverImplTest* test; 450 HostResolverImplTest* test;
436 }; 451 };
437 452
438 void CreateResolver() { 453 // testing::Test implementation:
439 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), 454 virtual void SetUp() OVERRIDE {
440 DefaultLimits(), 455 CreateResolver();
441 DefaultParams(proc_.get()),
442 NULL));
443 } 456 }
444 457
445 // This HostResolverImpl will only allow 1 outstanding resolve at a time and 458 virtual void TearDown() OVERRIDE {
446 // perform no retries. 459 if (resolver_.get())
447 void CreateSerialResolver() { 460 EXPECT_EQ(0u, resolver_->num_running_dispatcher_jobs_for_tests());
448 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get()); 461 EXPECT_FALSE(proc_->HasBlockedRequests());
449 params.max_retry_attempts = 0u; 462 }
450 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); 463
451 resolver_.reset(new HostResolverImpl( 464 virtual void CreateResolverWithLimitsAndParams(
452 HostCache::CreateDefaultCache(), 465 const PrioritizedDispatcher::Limits& limits,
453 limits, 466 const HostResolverImpl::ProcTaskParams& params) {
454 params, 467 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
455 NULL)); 468 limits, params, NULL));
456 } 469 }
457 470
458 // The Request will not be made until a call to |Resolve()|, and the Job will 471 // The Request will not be made until a call to |Resolve()|, and the Job will
459 // not start until released by |proc_->SignalXXX|. 472 // not start until released by |proc_->SignalXXX|.
460 Request* CreateRequest(const HostResolver::RequestInfo& info) { 473 Request* CreateRequest(const HostResolver::RequestInfo& info) {
461 Request* req = new Request(info, requests_.size(), resolver_.get(), 474 Request* req = new Request(info, requests_.size(), resolver_.get(),
462 handler_.get()); 475 handler_.get());
463 requests_.push_back(req); 476 requests_.push_back(req);
464 return req; 477 return req;
465 } 478 }
(...skipping 15 matching lines...) Expand all
481 } 494 }
482 495
483 Request* CreateRequest(const std::string& hostname, int port) { 496 Request* CreateRequest(const std::string& hostname, int port) {
484 return CreateRequest(hostname, port, MEDIUM); 497 return CreateRequest(hostname, port, MEDIUM);
485 } 498 }
486 499
487 Request* CreateRequest(const std::string& hostname) { 500 Request* CreateRequest(const std::string& hostname) {
488 return CreateRequest(hostname, kDefaultPort); 501 return CreateRequest(hostname, kDefaultPort);
489 } 502 }
490 503
491 virtual void SetUp() OVERRIDE {
492 CreateResolver();
493 }
494
495 virtual void TearDown() OVERRIDE {
496 if (resolver_.get())
497 EXPECT_EQ(0u, resolver_->num_running_jobs_for_tests());
498 EXPECT_FALSE(proc_->HasBlockedRequests());
499 }
500
501 void set_handler(Handler* handler) { 504 void set_handler(Handler* handler) {
502 handler_.reset(handler); 505 handler_.reset(handler);
503 handler_->test = this; 506 handler_->test = this;
504 } 507 }
505 508
506 // Friendship is not inherited, so use proxies to access those. 509 // Friendship is not inherited, so use proxies to access those.
507 size_t num_running_jobs() const { 510 size_t num_running_dispatcher_jobs() const {
508 DCHECK(resolver_.get()); 511 DCHECK(resolver_.get());
509 return resolver_->num_running_jobs_for_tests(); 512 return resolver_->num_running_dispatcher_jobs_for_tests();
510 } 513 }
511 514
512 void set_fallback_to_proctask(bool fallback_to_proctask) { 515 void set_fallback_to_proctask(bool fallback_to_proctask) {
513 DCHECK(resolver_.get()); 516 DCHECK(resolver_.get());
514 resolver_->fallback_to_proctask_ = fallback_to_proctask; 517 resolver_->fallback_to_proctask_ = fallback_to_proctask;
515 } 518 }
516 519
517 scoped_refptr<MockHostResolverProc> proc_; 520 scoped_refptr<MockHostResolverProc> proc_;
518 scoped_ptr<HostResolverImpl> resolver_; 521 scoped_ptr<HostResolverImpl> resolver_;
519 ScopedVector<Request> requests_; 522 ScopedVector<Request> requests_;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); 885 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve());
883 886
884 EXPECT_TRUE(proc_->WaitFor(1u)); 887 EXPECT_TRUE(proc_->WaitFor(1u));
885 // Triggering an IP address change. 888 // Triggering an IP address change.
886 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 889 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
887 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. 890 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async.
888 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. 891 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it.
889 892
890 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); 893 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult());
891 894
892 EXPECT_EQ(1u, num_running_jobs()); 895 EXPECT_EQ(1u, num_running_dispatcher_jobs());
893 896
894 EXPECT_FALSE(requests_[1]->completed()); 897 EXPECT_FALSE(requests_[1]->completed());
895 EXPECT_FALSE(requests_[2]->completed()); 898 EXPECT_FALSE(requests_[2]->completed());
896 899
897 EXPECT_EQ(OK, requests_[2]->WaitForResult()); 900 EXPECT_EQ(OK, requests_[2]->WaitForResult());
898 EXPECT_EQ(OK, requests_[1]->result()); 901 EXPECT_EQ(OK, requests_[1]->result());
899 } 902 }
900 903
901 // Tests that a new Request made from the callback of a previously aborted one 904 // Tests that a new Request made from the callback of a previously aborted one
902 // will not be aborted. 905 // will not be aborted.
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 EXPECT_TRUE(rv); 1251 EXPECT_TRUE(rv);
1249 1252
1250 DnsConfig config; 1253 DnsConfig config;
1251 config.nameservers.push_back(IPEndPoint(dns_ip, dns_protocol::kDefaultPort)); 1254 config.nameservers.push_back(IPEndPoint(dns_ip, dns_protocol::kDefaultPort));
1252 EXPECT_TRUE(config.IsValid()); 1255 EXPECT_TRUE(config.IsValid());
1253 return config; 1256 return config;
1254 } 1257 }
1255 1258
1256 // Specialized fixture for tests of DnsTask. 1259 // Specialized fixture for tests of DnsTask.
1257 class HostResolverImplDnsTest : public HostResolverImplTest { 1260 class HostResolverImplDnsTest : public HostResolverImplTest {
1261 public:
1262 HostResolverImplDnsTest() : dns_client_(NULL) {}
1263
1258 protected: 1264 protected:
1265 // testing::Test implementation:
1259 virtual void SetUp() OVERRIDE { 1266 virtual void SetUp() OVERRIDE {
1260 AddDnsRule("nx", dns_protocol::kTypeA, MockDnsClientRule::FAIL); 1267 AddDnsRule("nx", dns_protocol::kTypeA, MockDnsClientRule::FAIL, false);
1261 AddDnsRule("nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL); 1268 AddDnsRule("nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL, false);
1262 AddDnsRule("ok", dns_protocol::kTypeA, MockDnsClientRule::OK); 1269 AddDnsRule("ok", dns_protocol::kTypeA, MockDnsClientRule::OK, false);
1263 AddDnsRule("ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK); 1270 AddDnsRule("ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, false);
1264 AddDnsRule("4ok", dns_protocol::kTypeA, MockDnsClientRule::OK); 1271 AddDnsRule("4ok", dns_protocol::kTypeA, MockDnsClientRule::OK, false);
1265 AddDnsRule("4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY); 1272 AddDnsRule("4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY, false);
1266 AddDnsRule("6ok", dns_protocol::kTypeA, MockDnsClientRule::EMPTY); 1273 AddDnsRule("6ok", dns_protocol::kTypeA, MockDnsClientRule::EMPTY, false);
1267 AddDnsRule("6ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK); 1274 AddDnsRule("6ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, false);
1268 AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK); 1275 AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK, false);
1269 AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL); 1276 AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL, false);
1277
1278 AddDnsRule("4slow_ok", dns_protocol::kTypeA, MockDnsClientRule::OK, true);
1279 AddDnsRule("4slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK,
1280 false);
1281 AddDnsRule("6slow_ok", dns_protocol::kTypeA, MockDnsClientRule::OK, false);
1282 AddDnsRule("6slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK,
1283 true);
1284 AddDnsRule("4slow_4ok", dns_protocol::kTypeA, MockDnsClientRule::OK, true);
1285 AddDnsRule("4slow_4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY,
1286 false);
1287 AddDnsRule("4slow_4timeout", dns_protocol::kTypeA,
1288 MockDnsClientRule::TIMEOUT, true);
1289 AddDnsRule("4slow_4timeout", dns_protocol::kTypeAAAA, MockDnsClientRule::OK,
1290 false);
1291 AddDnsRule("4slow_6timeout", dns_protocol::kTypeA,
1292 MockDnsClientRule::OK, true);
1293 AddDnsRule("4slow_6timeout", dns_protocol::kTypeAAAA,
1294 MockDnsClientRule::TIMEOUT, false);
1270 CreateResolver(); 1295 CreateResolver();
1271 } 1296 }
1272 1297
1273 void CreateResolver() { 1298 // HostResolverImplTest implementation:
1299 virtual void CreateResolverWithLimitsAndParams(
1300 const PrioritizedDispatcher::Limits& limits,
1301 const HostResolverImpl::ProcTaskParams& params) OVERRIDE {
1274 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), 1302 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
1275 DefaultLimits(), 1303 limits,
1276 DefaultParams(proc_.get()), 1304 params,
1277 NULL)); 1305 NULL));
1278 // Disable IPv6 support probing. 1306 // Disable IPv6 support probing.
1279 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); 1307 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1280 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); 1308 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_);
1309 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_));
1281 } 1310 }
1282 1311
1283 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. 1312 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply.
1284 void AddDnsRule(const std::string& prefix, 1313 void AddDnsRule(const std::string& prefix,
1285 uint16 qtype, 1314 uint16 qtype,
1286 MockDnsClientRule::Result result) { 1315 MockDnsClientRule::Result result,
1287 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result)); 1316 bool delay) {
1317 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay));
1288 } 1318 }
1289 1319
1290 void ChangeDnsConfig(const DnsConfig& config) { 1320 void ChangeDnsConfig(const DnsConfig& config) {
1291 NetworkChangeNotifier::SetDnsConfig(config); 1321 NetworkChangeNotifier::SetDnsConfig(config);
1292 // Notification is delivered asynchronously. 1322 // Notification is delivered asynchronously.
1293 base::MessageLoop::current()->RunUntilIdle(); 1323 base::MessageLoop::current()->RunUntilIdle();
1294 } 1324 }
1295 1325
1296 MockDnsClientRuleList dns_rules_; 1326 MockDnsClientRuleList dns_rules_;
1327 MockDnsClient* dns_client_;
szym 2013/08/06 20:35:31 // Owned by |resolver_|.
mmenke 2013/08/19 17:31:11 Done.
1297 }; 1328 };
1298 1329
1299 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. 1330 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change.
1300 1331
1301 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. 1332 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags.
1302 1333
1303 // Test successful and fallback resolutions in HostResolverImpl::DnsTask. 1334 // Test successful and fallback resolutions in HostResolverImpl::DnsTask.
1304 TEST_F(HostResolverImplDnsTest, DnsTask) { 1335 TEST_F(HostResolverImplDnsTest, DnsTask) {
1305 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); 1336 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1306 1337
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 EXPECT_EQ(OK, requests_[1]->WaitForResult()); 1385 EXPECT_EQ(OK, requests_[1]->WaitForResult());
1355 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80)); 1386 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80));
1356 1387
1357 ChangeDnsConfig(CreateValidDnsConfig()); 1388 ChangeDnsConfig(CreateValidDnsConfig());
1358 1389
1359 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80)->Resolve()); 1390 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80)->Resolve());
1360 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); 1391 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve());
1361 1392
1362 // Simulate the case when the preference or policy has disabled the DNS client 1393 // Simulate the case when the preference or policy has disabled the DNS client
1363 // causing AbortDnsTasks. 1394 // causing AbortDnsTasks.
1364 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); 1395 resolver_->SetDnsClient(
1396 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_)));
1365 ChangeDnsConfig(CreateValidDnsConfig()); 1397 ChangeDnsConfig(CreateValidDnsConfig());
1366 1398
1367 // First request is resolved by MockDnsClient, others should fail due to 1399 // First request is resolved by MockDnsClient, others should fail due to
1368 // disabled fallback to ProcTask. 1400 // disabled fallback to ProcTask.
1369 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); 1401 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve());
1370 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80)->Resolve()); 1402 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80)->Resolve());
1371 proc_->SignalMultiple(requests_.size()); 1403 proc_->SignalMultiple(requests_.size());
1372 1404
1373 // Aborted due to Network Change. 1405 // Aborted due to Network Change.
1374 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->WaitForResult()); 1406 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->WaitForResult());
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 // Confirm that resolving "localhost" is unrestricted even if there are no 1610 // Confirm that resolving "localhost" is unrestricted even if there are no
1579 // global IPv6 address. See SystemHostResolverCall for rationale. 1611 // global IPv6 address. See SystemHostResolverCall for rationale.
1580 // Test both the DnsClient and system host resolver paths. 1612 // Test both the DnsClient and system host resolver paths.
1581 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { 1613 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) {
1582 // Use regular SystemHostResolverCall! 1614 // Use regular SystemHostResolverCall!
1583 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); 1615 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc());
1584 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), 1616 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
1585 DefaultLimits(), 1617 DefaultLimits(),
1586 DefaultParams(proc.get()), 1618 DefaultParams(proc.get()),
1587 NULL)); 1619 NULL));
1588 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); 1620 resolver_->SetDnsClient(
1621 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_)));
1589 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); 1622 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1590 1623
1591 // Get the expected output. 1624 // Get the expected output.
1592 AddressList addrlist; 1625 AddressList addrlist;
1593 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, 1626 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist,
1594 NULL); 1627 NULL);
1595 if (rv != OK) 1628 if (rv != OK)
1596 return; 1629 return;
1597 1630
1598 for (unsigned i = 0; i < addrlist.size(); ++i) 1631 for (unsigned i = 0; i < addrlist.size(); ++i)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 1664
1632 ChangeDnsConfig(config); 1665 ChangeDnsConfig(config);
1633 req = CreateRequest(info); 1666 req = CreateRequest(info);
1634 // Expect synchronous resolution from DnsHosts. 1667 // Expect synchronous resolution from DnsHosts.
1635 EXPECT_EQ(OK, req->Resolve()); 1668 EXPECT_EQ(OK, req->Resolve());
1636 1669
1637 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); 1670 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80));
1638 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); 1671 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80));
1639 } 1672 }
1640 1673
1674 // Cancel a request with a single DNS transaction active.
1675 TEST_F(HostResolverImplDnsTest, AsyncResolverCancelWithOneTransactionActive) {
szym 2013/08/06 20:35:31 No need for AsyncResolver prefix to these tests. A
mmenke 2013/08/19 17:31:11 Done (Though I think it's very easy to miss the "D
1676 set_fallback_to_proctask(false);
szym 2013/08/06 20:35:31 I don't think these tests need set_fallback_to_pro
mmenke 2013/08/19 17:31:11 Done.
1677 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1678 ChangeDnsConfig(CreateValidDnsConfig());
1679
1680 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve());
1681 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1682 requests_[0]->Cancel();
szym 2013/08/06 20:35:31 When the test depends on TearDown, suggest comment
mmenke 2013/08/19 17:31:11 Done.
1683 }
1684
1685 // Cancel a request with a single DNS transaction active and another pending.
1686 TEST_F(HostResolverImplDnsTest,
1687 AsyncResolverCancelWithOneTransactionActiveOnePending) {
1688 CreateSerialResolver();
1689 set_fallback_to_proctask(false);
1690 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1691 ChangeDnsConfig(CreateValidDnsConfig());
1692
1693 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve());
1694 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1695 requests_[0]->Cancel();
1696 }
1697
1698 // Cancel a request with two DNS transactions active.
1699 TEST_F(HostResolverImplDnsTest, AsyncResolverCancelWithTwoTransactionsActive) {
1700 set_fallback_to_proctask(false);
1701 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1702 ChangeDnsConfig(CreateValidDnsConfig());
1703
1704 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve());
1705 EXPECT_EQ(2u, num_running_dispatcher_jobs());
1706 requests_[0]->Cancel();
1707 }
1708
1709 // Cancel a request with only the IPv6 transaction active.
1710 TEST_F(HostResolverImplDnsTest, AsyncResolverCancelWithIPv6TransactionActive) {
1711 set_fallback_to_proctask(false);
1712 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1713 ChangeDnsConfig(CreateValidDnsConfig());
1714
1715 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("6slow_ok", 80)->Resolve());
1716 EXPECT_EQ(2u, num_running_dispatcher_jobs());
1717
1718 // The IPv4 request should complete, the IPv6 request is still pending.
1719 base::RunLoop().RunUntilIdle();
1720 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1721
1722 requests_[0]->Cancel();
1723 }
1724
1725 // Cancel a request with only the IPv4 transaction pending.
1726 TEST_F(HostResolverImplDnsTest, AsyncResolverCancelWithIPv4TransactionPending) {
1727 set_fallback_to_proctask(false);
1728 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1729 ChangeDnsConfig(CreateValidDnsConfig());
1730
1731 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve());
1732 EXPECT_EQ(2u, num_running_dispatcher_jobs());
1733
1734 // The IPv6 request should complete, the IPv4 request is still pending.
1735 base::RunLoop().RunUntilIdle();
1736 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1737
1738 requests_[0]->Cancel();
1739 }
1740
szym 2013/08/06 20:35:31 Add a test which ends in resolver_.Reset() without
mmenke 2013/08/19 17:31:11 Done (Added two, actually).
1741 // Test cases where AAAA completes first.
1742 TEST_F(HostResolverImplDnsTest, AAAACompletesFirst) {
1743 set_fallback_to_proctask(false);
szym 2013/08/06 20:35:31 OK. These three last tests do need fallback disabl
mmenke 2013/08/19 17:31:11 Yea, I wrote them first, and then just copied + pa
1744 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1745 ChangeDnsConfig(CreateValidDnsConfig());
1746
1747 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve());
1748 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4ok", 80)->Resolve());
1749 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4timeout", 80)->Resolve());
1750 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_6timeout", 80)->Resolve());
1751
1752 base::RunLoop().RunUntilIdle();
1753 EXPECT_FALSE(requests_[0]->completed());
1754 EXPECT_FALSE(requests_[1]->completed());
1755 EXPECT_FALSE(requests_[2]->completed());
1756 // The IPv6 of the third request should have failed and resulted in cancelling
1757 // the IPv4 request.
1758 EXPECT_TRUE(requests_[3]->completed());
1759 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[3]->result());
1760 EXPECT_EQ(3u, num_running_dispatcher_jobs());
1761
1762 dns_client_->CompleteDelayedTransactions();
1763 EXPECT_TRUE(requests_[0]->completed());
1764 EXPECT_EQ(OK, requests_[0]->result());
1765 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses());
1766 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80));
1767 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80));
1768
1769 EXPECT_TRUE(requests_[1]->completed());
1770 EXPECT_EQ(OK, requests_[1]->result());
1771 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses());
1772 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80));
1773
1774 EXPECT_TRUE(requests_[2]->completed());
1775 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[2]->result());
1776 }
1777
1778 // Test the case where only a single transaction slot is available.
1779 TEST_F(HostResolverImplDnsTest, SerialResolver) {
1780 CreateSerialResolver();
1781 set_fallback_to_proctask(false);
1782 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1783 ChangeDnsConfig(CreateValidDnsConfig());
1784
1785 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve());
1786 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1787
1788 base::RunLoop().RunUntilIdle();
1789 EXPECT_TRUE(requests_[0]->completed());
1790 EXPECT_EQ(OK, requests_[0]->result());
1791 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses());
1792 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80));
1793 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80));
1794 }
1795
1796 // Test the case where the AAAA query is started when another transaction
1797 // completes.
1798 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) {
1799 CreateResolverWithLimitsAndParams(
1800 PrioritizedDispatcher::Limits(NUM_PRIORITIES, 2),
1801 DefaultParams(proc_.get()));
1802 set_fallback_to_proctask(false);
1803 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1804 ChangeDnsConfig(CreateValidDnsConfig());
1805
1806 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM,
szym 2013/08/06 20:35:31 MEDIUM is the default priority in CreateRequest.
mmenke 2013/08/19 17:31:11 There's no overload that takes an address family,
szym 2013/08/19 18:47:21 I totally missed that this request is IPV4 only. S
1807 ADDRESS_FAMILY_IPV4)->Resolve());
1808 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve());
szym 2013/08/06 20:35:31 Maybe make the priority explicit here.
mmenke 2013/08/19 17:31:11 Done.
1809 // An IPv4 request should have been started pending for each job.
szym 2013/08/06 20:35:31 Actually, the first Resolve() call will cause the
mmenke 2013/08/19 17:31:11 The first resolve only has one transaction (It's I
mmenke 2013/08/19 18:12:08 To give a better explanation of how this works: R
szym 2013/08/19 18:47:21 I understand now. It all makes sense once I notice
1810 EXPECT_EQ(2u, num_running_dispatcher_jobs());
1811
1812 // Request 0's IPv4 request should complete, starting Request 1's IPv6
1813 // request, which should also complete.
1814 base::RunLoop().RunUntilIdle();
1815 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1816 EXPECT_TRUE(requests_[0]->completed());
1817 EXPECT_FALSE(requests_[1]->completed());
1818
1819 dns_client_->CompleteDelayedTransactions();
1820 EXPECT_TRUE(requests_[1]->completed());
1821 EXPECT_EQ(OK, requests_[1]->result());
1822 EXPECT_EQ(2u, requests_[1]->NumberOfAddresses());
1823 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80));
1824 EXPECT_TRUE(requests_[1]->HasAddress("::1", 80));
1825 }
1826
1641 } // namespace net 1827 } // namespace net
OLDNEW
« net/dns/host_resolver_impl.cc ('K') | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698