| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using base::TimeTicks; | 34 using base::TimeTicks; |
| 35 | 35 |
| 36 HostCache* CreateDefaultCache() { | 36 HostCache* CreateDefaultCache() { |
| 37 return new HostCache( | 37 return new HostCache( |
| 38 100, // max cache entries. | 38 100, // max cache entries. |
| 39 base::TimeDelta::FromMinutes(1), | 39 base::TimeDelta::FromMinutes(1), |
| 40 base::TimeDelta::FromSeconds(0)); | 40 base::TimeDelta::FromSeconds(0)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 static const size_t kMaxJobs = 10u; | 43 static const size_t kMaxJobs = 10u; |
| 44 static const size_t kMaxRetryAttempts = 4u; |
| 44 | 45 |
| 45 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { | 46 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { |
| 46 return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 47 return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
| 47 NULL); | 48 kMaxRetryAttempts, NULL); |
| 48 } | 49 } |
| 49 | 50 |
| 50 // Helper to create a HostResolver::RequestInfo. | 51 // Helper to create a HostResolver::RequestInfo. |
| 51 HostResolver::RequestInfo CreateResolverRequest( | 52 HostResolver::RequestInfo CreateResolverRequest( |
| 52 const std::string& hostname, | 53 const std::string& hostname, |
| 53 RequestPriority priority) { | 54 RequestPriority priority) { |
| 54 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); | 55 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); |
| 55 info.set_priority(priority); | 56 info.set_priority(priority); |
| 56 return info; | 57 return info; |
| 57 } | 58 } |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 445 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| 445 new WaitingHostResolverProc(NULL)); | 446 new WaitingHostResolverProc(NULL)); |
| 446 | 447 |
| 447 CapturingNetLog net_log(CapturingNetLog::kUnbounded); | 448 CapturingNetLog net_log(CapturingNetLog::kUnbounded); |
| 448 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 449 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 449 { | 450 { |
| 450 scoped_ptr<HostResolver> host_resolver( | 451 scoped_ptr<HostResolver> host_resolver( |
| 451 new HostResolverImpl(resolver_proc, | 452 new HostResolverImpl(resolver_proc, |
| 452 CreateDefaultCache(), | 453 CreateDefaultCache(), |
| 453 kMaxJobs, | 454 kMaxJobs, |
| 455 kMaxRetryAttempts, |
| 454 &net_log)); | 456 &net_log)); |
| 455 AddressList addrlist; | 457 AddressList addrlist; |
| 456 const int kPortnum = 80; | 458 const int kPortnum = 80; |
| 457 | 459 |
| 458 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 460 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
| 459 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, | 461 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, |
| 460 log.bound()); | 462 log.bound()); |
| 461 EXPECT_EQ(ERR_IO_PENDING, err); | 463 EXPECT_EQ(ERR_IO_PENDING, err); |
| 462 | 464 |
| 463 // Make sure we will exit the queue even when callback is not called. | 465 // Make sure we will exit the queue even when callback is not called. |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 | 892 |
| 891 TEST_F(HostResolverImplTest, StartWithinCallback) { | 893 TEST_F(HostResolverImplTest, StartWithinCallback) { |
| 892 // Use a capturing resolver_proc, since the verifier needs to know what calls | 894 // Use a capturing resolver_proc, since the verifier needs to know what calls |
| 893 // reached Resolver(). Also, the capturing resolver_proc is initially | 895 // reached Resolver(). Also, the capturing resolver_proc is initially |
| 894 // blocked. | 896 // blocked. |
| 895 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 897 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 896 new CapturingHostResolverProc(NULL)); | 898 new CapturingHostResolverProc(NULL)); |
| 897 | 899 |
| 898 // Turn off caching for this host resolver. | 900 // Turn off caching for this host resolver. |
| 899 scoped_ptr<HostResolver> host_resolver( | 901 scoped_ptr<HostResolver> host_resolver( |
| 900 new HostResolverImpl(resolver_proc, NULL, kMaxJobs, NULL)); | 902 new HostResolverImpl(resolver_proc, NULL, kMaxJobs, kMaxRetryAttempts, |
| 903 NULL)); |
| 901 | 904 |
| 902 // The class will receive callbacks for when each resolve completes. It | 905 // The class will receive callbacks for when each resolve completes. It |
| 903 // checks that the right things happened. | 906 // checks that the right things happened. |
| 904 StartWithinCallbackVerifier verifier; | 907 StartWithinCallbackVerifier verifier; |
| 905 | 908 |
| 906 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is | 909 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is |
| 907 // blocked, these should all pile up until we signal it. | 910 // blocked, these should all pile up until we signal it. |
| 908 | 911 |
| 909 ResolveRequest req1(host_resolver.get(), "a", 80, &verifier); | 912 ResolveRequest req1(host_resolver.get(), "a", 80, &verifier); |
| 910 ResolveRequest req2(host_resolver.get(), "a", 81, &verifier); | 913 ResolveRequest req2(host_resolver.get(), "a", 81, &verifier); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 EXPECT_EQ(2U, observer.cancel_log.size()); | 1193 EXPECT_EQ(2U, observer.cancel_log.size()); |
| 1191 | 1194 |
| 1192 HostResolver::RequestInfo info(HostPortPair("host2", 60)); | 1195 HostResolver::RequestInfo info(HostPortPair("host2", 60)); |
| 1193 EXPECT_TRUE(observer.cancel_log[1] == | 1196 EXPECT_TRUE(observer.cancel_log[1] == |
| 1194 CapturingObserver::StartOrCancelEntry(1, info)); | 1197 CapturingObserver::StartOrCancelEntry(1, info)); |
| 1195 } | 1198 } |
| 1196 | 1199 |
| 1197 // Test that IP address changes flush the cache. | 1200 // Test that IP address changes flush the cache. |
| 1198 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 1201 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
| 1199 scoped_ptr<HostResolver> host_resolver( | 1202 scoped_ptr<HostResolver> host_resolver( |
| 1200 new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, NULL)); | 1203 new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, |
| 1204 kMaxRetryAttempts, NULL)); |
| 1201 | 1205 |
| 1202 AddressList addrlist; | 1206 AddressList addrlist; |
| 1203 | 1207 |
| 1204 // Resolve "host1". | 1208 // Resolve "host1". |
| 1205 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); | 1209 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); |
| 1206 TestCompletionCallback callback; | 1210 TestCompletionCallback callback; |
| 1207 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, | 1211 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, |
| 1208 BoundNetLog()); | 1212 BoundNetLog()); |
| 1209 EXPECT_EQ(ERR_IO_PENDING, rv); | 1213 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1210 EXPECT_EQ(OK, callback.WaitForResult()); | 1214 EXPECT_EQ(OK, callback.WaitForResult()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1224 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. | 1228 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. |
| 1225 EXPECT_EQ(OK, callback.WaitForResult()); | 1229 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1226 } | 1230 } |
| 1227 | 1231 |
| 1228 // Test that IP address changes send ERR_ABORTED to pending requests. | 1232 // Test that IP address changes send ERR_ABORTED to pending requests. |
| 1229 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { | 1233 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
| 1230 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 1234 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| 1231 new WaitingHostResolverProc(NULL)); | 1235 new WaitingHostResolverProc(NULL)); |
| 1232 HostCache* cache = CreateDefaultCache(); | 1236 HostCache* cache = CreateDefaultCache(); |
| 1233 scoped_ptr<HostResolver> host_resolver( | 1237 scoped_ptr<HostResolver> host_resolver( |
| 1234 new HostResolverImpl(resolver_proc, cache, kMaxJobs, NULL)); | 1238 new HostResolverImpl(resolver_proc, cache, kMaxJobs, kMaxRetryAttempts, |
| 1239 NULL)); |
| 1235 | 1240 |
| 1236 // Resolve "host1". | 1241 // Resolve "host1". |
| 1237 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1242 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
| 1238 TestCompletionCallback callback; | 1243 TestCompletionCallback callback; |
| 1239 AddressList addrlist; | 1244 AddressList addrlist; |
| 1240 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1245 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, |
| 1241 BoundNetLog()); | 1246 BoundNetLog()); |
| 1242 EXPECT_EQ(ERR_IO_PENDING, rv); | 1247 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1243 | 1248 |
| 1244 // Triggering an IP address change. | 1249 // Triggering an IP address change. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 } | 1352 } |
| 1348 | 1353 |
| 1349 // Tests that when the maximum threads is set to 1, requests are dequeued | 1354 // Tests that when the maximum threads is set to 1, requests are dequeued |
| 1350 // in order of priority. | 1355 // in order of priority. |
| 1351 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1356 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
| 1352 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1357 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1353 new CapturingHostResolverProc(NULL)); | 1358 new CapturingHostResolverProc(NULL)); |
| 1354 | 1359 |
| 1355 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1360 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1356 size_t kMaxJobs = 1u; | 1361 size_t kMaxJobs = 1u; |
| 1362 const size_t kRetryAttempts = 0u; |
| 1357 scoped_ptr<HostResolver> host_resolver( | 1363 scoped_ptr<HostResolver> host_resolver( |
| 1358 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 1364 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
| 1359 NULL)); | 1365 kRetryAttempts, NULL)); |
| 1360 | 1366 |
| 1361 CapturingObserver observer; | 1367 CapturingObserver observer; |
| 1362 host_resolver->AddObserver(&observer); | 1368 host_resolver->AddObserver(&observer); |
| 1363 | 1369 |
| 1364 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1370 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1365 // requests we make will not complete. | 1371 // requests we make will not complete. |
| 1366 | 1372 |
| 1367 HostResolver::RequestInfo req[] = { | 1373 HostResolver::RequestInfo req[] = { |
| 1368 CreateResolverRequest("req0", LOW), | 1374 CreateResolverRequest("req0", LOW), |
| 1369 CreateResolverRequest("req1", MEDIUM), | 1375 CreateResolverRequest("req1", MEDIUM), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 EXPECT_EQ("req6", observer.finish_log[7].info.hostname()); | 1438 EXPECT_EQ("req6", observer.finish_log[7].info.hostname()); |
| 1433 } | 1439 } |
| 1434 | 1440 |
| 1435 // Try cancelling a request which has not been attached to a job yet. | 1441 // Try cancelling a request which has not been attached to a job yet. |
| 1436 TEST_F(HostResolverImplTest, CancelPendingRequest) { | 1442 TEST_F(HostResolverImplTest, CancelPendingRequest) { |
| 1437 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1443 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1438 new CapturingHostResolverProc(NULL)); | 1444 new CapturingHostResolverProc(NULL)); |
| 1439 | 1445 |
| 1440 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1446 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1441 const size_t kMaxJobs = 1u; | 1447 const size_t kMaxJobs = 1u; |
| 1448 const size_t kRetryAttempts = 0u; |
| 1442 scoped_ptr<HostResolver> host_resolver( | 1449 scoped_ptr<HostResolver> host_resolver( |
| 1443 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 1450 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
| 1444 NULL)); | 1451 kRetryAttempts, NULL)); |
| 1445 | 1452 |
| 1446 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1453 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1447 // requests we make will not complete. | 1454 // requests we make will not complete. |
| 1448 | 1455 |
| 1449 HostResolver::RequestInfo req[] = { | 1456 HostResolver::RequestInfo req[] = { |
| 1450 CreateResolverRequest("req0", LOWEST), | 1457 CreateResolverRequest("req0", LOWEST), |
| 1451 CreateResolverRequest("req1", HIGHEST), // Will cancel. | 1458 CreateResolverRequest("req1", HIGHEST), // Will cancel. |
| 1452 CreateResolverRequest("req2", MEDIUM), | 1459 CreateResolverRequest("req2", MEDIUM), |
| 1453 CreateResolverRequest("req3", LOW), | 1460 CreateResolverRequest("req3", LOW), |
| 1454 CreateResolverRequest("req4", HIGHEST), // Will cancel. | 1461 CreateResolverRequest("req4", HIGHEST), // Will cancel. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 EXPECT_EQ("req3", capture_list[3].hostname); | 1502 EXPECT_EQ("req3", capture_list[3].hostname); |
| 1496 } | 1503 } |
| 1497 | 1504 |
| 1498 // Test that when too many requests are enqueued, old ones start to be aborted. | 1505 // Test that when too many requests are enqueued, old ones start to be aborted. |
| 1499 TEST_F(HostResolverImplTest, QueueOverflow) { | 1506 TEST_F(HostResolverImplTest, QueueOverflow) { |
| 1500 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1507 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1501 new CapturingHostResolverProc(NULL)); | 1508 new CapturingHostResolverProc(NULL)); |
| 1502 | 1509 |
| 1503 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1510 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1504 const size_t kMaxOutstandingJobs = 1u; | 1511 const size_t kMaxOutstandingJobs = 1u; |
| 1512 const size_t kRetryAttempts = 0u; |
| 1505 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1513 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1506 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1514 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, kRetryAttempts, |
| 1515 NULL)); |
| 1507 | 1516 |
| 1508 // Only allow up to 3 requests to be enqueued at a time. | 1517 // Only allow up to 3 requests to be enqueued at a time. |
| 1509 const size_t kMaxPendingRequests = 3u; | 1518 const size_t kMaxPendingRequests = 3u; |
| 1510 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, | 1519 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
| 1511 kMaxOutstandingJobs, | 1520 kMaxOutstandingJobs, |
| 1512 kMaxPendingRequests); | 1521 kMaxPendingRequests); |
| 1513 | 1522 |
| 1514 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1523 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1515 // requests we make will not complete. | 1524 // requests we make will not complete. |
| 1516 | 1525 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 } | 1582 } |
| 1574 | 1583 |
| 1575 // Tests that after changing the default AddressFamily to IPV4, requests | 1584 // Tests that after changing the default AddressFamily to IPV4, requests |
| 1576 // with UNSPECIFIED address family map to IPV4. | 1585 // with UNSPECIFIED address family map to IPV4. |
| 1577 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { | 1586 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { |
| 1578 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1587 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1579 new CapturingHostResolverProc(new EchoingHostResolverProc)); | 1588 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| 1580 | 1589 |
| 1581 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1590 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1582 const size_t kMaxOutstandingJobs = 1u; | 1591 const size_t kMaxOutstandingJobs = 1u; |
| 1592 const size_t kRetryAttempts = 0u; |
| 1583 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1593 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1584 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1594 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, kRetryAttempts, |
| 1595 NULL)); |
| 1585 | 1596 |
| 1586 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1597 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1587 | 1598 |
| 1588 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1599 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1589 // requests we make will not complete. | 1600 // requests we make will not complete. |
| 1590 | 1601 |
| 1591 HostResolver::RequestInfo req[] = { | 1602 HostResolver::RequestInfo req[] = { |
| 1592 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1603 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1593 ADDRESS_FAMILY_UNSPECIFIED), | 1604 ADDRESS_FAMILY_UNSPECIFIED), |
| 1594 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), | 1605 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 | 1652 |
| 1642 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order | 1653 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order |
| 1643 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of | 1654 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of |
| 1644 // IPv4. | 1655 // IPv4. |
| 1645 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { | 1656 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { |
| 1646 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1657 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1647 new CapturingHostResolverProc(new EchoingHostResolverProc)); | 1658 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| 1648 | 1659 |
| 1649 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1660 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1650 const size_t kMaxOutstandingJobs = 1u; | 1661 const size_t kMaxOutstandingJobs = 1u; |
| 1662 const size_t kRetryAttempts = 0u; |
| 1651 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1663 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1652 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1664 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, kRetryAttempts, |
| 1665 NULL)); |
| 1653 | 1666 |
| 1654 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); | 1667 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); |
| 1655 | 1668 |
| 1656 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1669 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1657 // requests we make will not complete. | 1670 // requests we make will not complete. |
| 1658 | 1671 |
| 1659 HostResolver::RequestInfo req[] = { | 1672 HostResolver::RequestInfo req[] = { |
| 1660 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), | 1673 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), |
| 1661 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1674 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1662 ADDRESS_FAMILY_UNSPECIFIED), | 1675 ADDRESS_FAMILY_UNSPECIFIED), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[1].head())); | 1719 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[1].head())); |
| 1707 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); | 1720 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); |
| 1708 } | 1721 } |
| 1709 | 1722 |
| 1710 // This tests that the default address family is respected for synchronous | 1723 // This tests that the default address family is respected for synchronous |
| 1711 // resolutions. | 1724 // resolutions. |
| 1712 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { | 1725 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { |
| 1713 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1726 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1714 new CapturingHostResolverProc(new EchoingHostResolverProc)); | 1727 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| 1715 | 1728 |
| 1716 const size_t kMaxOutstandingJobs = 10u; | |
| 1717 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1729 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1718 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1730 resolver_proc, CreateDefaultCache(), kMaxJobs, kMaxRetryAttempts, NULL)); |
| 1719 | 1731 |
| 1720 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1732 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1721 | 1733 |
| 1722 // Unblock the resolver thread so the requests can run. | 1734 // Unblock the resolver thread so the requests can run. |
| 1723 resolver_proc->Signal(); | 1735 resolver_proc->Signal(); |
| 1724 | 1736 |
| 1725 HostResolver::RequestInfo req[] = { | 1737 HostResolver::RequestInfo req[] = { |
| 1726 CreateResolverRequestForAddressFamily("b", MEDIUM, | 1738 CreateResolverRequestForAddressFamily("b", MEDIUM, |
| 1727 ADDRESS_FAMILY_UNSPECIFIED), | 1739 ADDRESS_FAMILY_UNSPECIFIED), |
| 1728 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), | 1740 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1807 // word that a resolution has completed. The 3rd resolution attempt will try | 1819 // word that a resolution has completed. The 3rd resolution attempt will try |
| 1808 // to get done ASAP, and won't sleep.. | 1820 // to get done ASAP, and won't sleep.. |
| 1809 int kAttemptNumberToResolve = 3; | 1821 int kAttemptNumberToResolve = 3; |
| 1810 int kTotalAttempts = 3; | 1822 int kTotalAttempts = 3; |
| 1811 | 1823 |
| 1812 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( | 1824 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( |
| 1813 new LookupAttemptHostResolverProc( | 1825 new LookupAttemptHostResolverProc( |
| 1814 NULL, kAttemptNumberToResolve, kTotalAttempts)); | 1826 NULL, kAttemptNumberToResolve, kTotalAttempts)); |
| 1815 HostCache* cache = CreateDefaultCache(); | 1827 HostCache* cache = CreateDefaultCache(); |
| 1816 scoped_ptr<HostResolverImpl> host_resolver( | 1828 scoped_ptr<HostResolverImpl> host_resolver( |
| 1817 new HostResolverImpl(resolver_proc, cache, kMaxJobs, NULL)); | 1829 new HostResolverImpl(resolver_proc, cache, kMaxJobs, kMaxRetryAttempts, |
| 1830 NULL)); |
| 1818 | 1831 |
| 1819 // Specify smaller interval for unresponsive_delay_ and | 1832 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so |
| 1820 // maximum_unresponsive_delay_ for HostResolverImpl so that unit test | 1833 // that unit test runs faster. For example, this test finishes in 1.5 secs |
| 1821 // runs faster. For example, this test finishes in 1.5 secs (500ms * 3). | 1834 // (500ms * 3). |
| 1822 TimeDelta kUnresponsiveTime = TimeDelta::FromMilliseconds(500); | 1835 TimeDelta kUnresponsiveTime = TimeDelta::FromMilliseconds(500); |
| 1823 TimeDelta kMaximumUnresponsiveTime = TimeDelta::FromMilliseconds(2500); | |
| 1824 | |
| 1825 host_resolver->set_unresponsive_delay(kUnresponsiveTime); | 1836 host_resolver->set_unresponsive_delay(kUnresponsiveTime); |
| 1826 host_resolver->set_maximum_unresponsive_delay(kMaximumUnresponsiveTime); | |
| 1827 | 1837 |
| 1828 // Resolve "host1". | 1838 // Resolve "host1". |
| 1829 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1839 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
| 1830 TestCompletionCallback callback; | 1840 TestCompletionCallback callback; |
| 1831 AddressList addrlist; | 1841 AddressList addrlist; |
| 1832 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1842 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, |
| 1833 BoundNetLog()); | 1843 BoundNetLog()); |
| 1834 EXPECT_EQ(ERR_IO_PENDING, rv); | 1844 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1835 | 1845 |
| 1836 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. | 1846 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. |
| 1837 EXPECT_EQ(-4, callback.WaitForResult()); | 1847 EXPECT_EQ(-4, callback.WaitForResult()); |
| 1838 | 1848 |
| 1839 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); | 1849 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); |
| 1840 MessageLoop::current()->RunAllPending(); | 1850 MessageLoop::current()->RunAllPending(); |
| 1841 | 1851 |
| 1842 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1852 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
| 1843 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1853 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
| 1844 } | 1854 } |
| 1845 | 1855 |
| 1846 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1856 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1847 | 1857 |
| 1848 } // namespace net | 1858 } // namespace net |
| OLD | NEW |