| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/synchronization/condition_variable.h" | 14 #include "base/synchronization/condition_variable.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "net/base/address_list.h" | 17 #include "net/base/address_list.h" |
| 18 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
| 19 #include "net/base/dns_test_util.h" | 19 #include "net/base/dns_test_util.h" |
| 20 #include "net/base/host_cache.h" |
| 20 #include "net/base/mock_host_resolver.h" | 21 #include "net/base/mock_host_resolver.h" |
| 21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 22 #include "net/base/net_log_unittest.h" | 23 #include "net/base/net_log_unittest.h" |
| 23 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 24 #include "net/base/sys_addrinfo.h" | 25 #include "net/base/sys_addrinfo.h" |
| 25 #include "net/base/test_completion_callback.h" | 26 #include "net/base/test_completion_callback.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 // TODO(eroman): | 29 // TODO(eroman): |
| 29 // - Test mixing async with sync (in particular how does sync update the | 30 // - Test mixing async with sync (in particular how does sync update the |
| 30 // cache while an async is already pending). | 31 // cache while an async is already pending). |
| 31 | 32 |
| 32 namespace net { | 33 namespace net { |
| 33 | 34 |
| 34 using base::TimeDelta; | 35 using base::TimeDelta; |
| 35 using base::TimeTicks; | 36 using base::TimeTicks; |
| 36 | 37 |
| 37 HostCache* CreateDefaultCache() { | |
| 38 return new HostCache( | |
| 39 100, // max cache entries. | |
| 40 base::TimeDelta::FromMinutes(1), | |
| 41 base::TimeDelta::FromSeconds(0)); | |
| 42 } | |
| 43 | |
| 44 static const size_t kMaxJobs = 10u; | 38 static const size_t kMaxJobs = 10u; |
| 45 static const size_t kMaxRetryAttempts = 4u; | 39 static const size_t kMaxRetryAttempts = 4u; |
| 46 | 40 |
| 47 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { | 41 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { |
| 48 return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 42 return new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
| 49 kMaxRetryAttempts, NULL); | 43 kMaxJobs, kMaxRetryAttempts, NULL); |
| 50 } | 44 } |
| 51 | 45 |
| 52 // Helper to create a HostResolver::RequestInfo. | 46 // Helper to create a HostResolver::RequestInfo. |
| 53 HostResolver::RequestInfo CreateResolverRequest( | 47 HostResolver::RequestInfo CreateResolverRequest( |
| 54 const std::string& hostname, | 48 const std::string& hostname, |
| 55 RequestPriority priority) { | 49 RequestPriority priority) { |
| 56 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); | 50 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); |
| 57 info.set_priority(priority); | 51 info.set_priority(priority); |
| 58 return info; | 52 return info; |
| 59 } | 53 } |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 438 |
| 445 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { | 439 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { |
| 446 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 440 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| 447 new WaitingHostResolverProc(NULL)); | 441 new WaitingHostResolverProc(NULL)); |
| 448 | 442 |
| 449 CapturingNetLog net_log(CapturingNetLog::kUnbounded); | 443 CapturingNetLog net_log(CapturingNetLog::kUnbounded); |
| 450 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 444 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 451 { | 445 { |
| 452 scoped_ptr<HostResolver> host_resolver( | 446 scoped_ptr<HostResolver> host_resolver( |
| 453 new HostResolverImpl(resolver_proc, | 447 new HostResolverImpl(resolver_proc, |
| 454 CreateDefaultCache(), | 448 HostCache::CreateDefaultCache(), |
| 455 kMaxJobs, | 449 kMaxJobs, |
| 456 kMaxRetryAttempts, | 450 kMaxRetryAttempts, |
| 457 &net_log)); | 451 &net_log)); |
| 458 AddressList addrlist; | 452 AddressList addrlist; |
| 459 const int kPortnum = 80; | 453 const int kPortnum = 80; |
| 460 | 454 |
| 461 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 455 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
| 462 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, | 456 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, |
| 463 log.bound()); | 457 log.bound()); |
| 464 EXPECT_EQ(ERR_IO_PENDING, err); | 458 EXPECT_EQ(ERR_IO_PENDING, err); |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 EXPECT_EQ(2U, observer.cancel_log.size()); | 1121 EXPECT_EQ(2U, observer.cancel_log.size()); |
| 1128 | 1122 |
| 1129 HostResolver::RequestInfo info(HostPortPair("host2", 60)); | 1123 HostResolver::RequestInfo info(HostPortPair("host2", 60)); |
| 1130 EXPECT_TRUE(observer.cancel_log[1] == | 1124 EXPECT_TRUE(observer.cancel_log[1] == |
| 1131 TestHostResolverObserver::StartOrCancelEntry(1, info)); | 1125 TestHostResolverObserver::StartOrCancelEntry(1, info)); |
| 1132 } | 1126 } |
| 1133 | 1127 |
| 1134 // Test that IP address changes flush the cache. | 1128 // Test that IP address changes flush the cache. |
| 1135 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 1129 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
| 1136 scoped_ptr<HostResolver> host_resolver( | 1130 scoped_ptr<HostResolver> host_resolver( |
| 1137 new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, | 1131 new HostResolverImpl(NULL, HostCache::CreateDefaultCache(), kMaxJobs, |
| 1138 kMaxRetryAttempts, NULL)); | 1132 kMaxRetryAttempts, NULL)); |
| 1139 | 1133 |
| 1140 AddressList addrlist; | 1134 AddressList addrlist; |
| 1141 | 1135 |
| 1142 // Resolve "host1". | 1136 // Resolve "host1". |
| 1143 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); | 1137 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); |
| 1144 TestCompletionCallback callback; | 1138 TestCompletionCallback callback; |
| 1145 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, | 1139 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, |
| 1146 BoundNetLog()); | 1140 BoundNetLog()); |
| 1147 EXPECT_EQ(ERR_IO_PENDING, rv); | 1141 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1160 // will complete asynchronously. | 1154 // will complete asynchronously. |
| 1161 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); | 1155 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); |
| 1162 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. | 1156 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. |
| 1163 EXPECT_EQ(OK, callback.WaitForResult()); | 1157 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1164 } | 1158 } |
| 1165 | 1159 |
| 1166 // Test that IP address changes send ERR_ABORTED to pending requests. | 1160 // Test that IP address changes send ERR_ABORTED to pending requests. |
| 1167 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { | 1161 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
| 1168 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 1162 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| 1169 new WaitingHostResolverProc(NULL)); | 1163 new WaitingHostResolverProc(NULL)); |
| 1170 HostCache* cache = CreateDefaultCache(); | 1164 HostCache* cache = HostCache::CreateDefaultCache(); |
| 1171 scoped_ptr<HostResolver> host_resolver( | 1165 scoped_ptr<HostResolver> host_resolver( |
| 1172 new HostResolverImpl(resolver_proc, cache, kMaxJobs, kMaxRetryAttempts, | 1166 new HostResolverImpl(resolver_proc, cache, kMaxJobs, kMaxRetryAttempts, |
| 1173 NULL)); | 1167 NULL)); |
| 1174 | 1168 |
| 1175 // Resolve "host1". | 1169 // Resolve "host1". |
| 1176 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1170 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
| 1177 TestCompletionCallback callback; | 1171 TestCompletionCallback callback; |
| 1178 AddressList addrlist; | 1172 AddressList addrlist; |
| 1179 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1173 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, |
| 1180 BoundNetLog()); | 1174 BoundNetLog()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 // Tests that when the maximum threads is set to 1, requests are dequeued | 1282 // Tests that when the maximum threads is set to 1, requests are dequeued |
| 1289 // in order of priority. | 1283 // in order of priority. |
| 1290 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1284 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
| 1291 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1285 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1292 new CapturingHostResolverProc(NULL)); | 1286 new CapturingHostResolverProc(NULL)); |
| 1293 | 1287 |
| 1294 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1288 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1295 size_t kMaxJobs = 1u; | 1289 size_t kMaxJobs = 1u; |
| 1296 const size_t kRetryAttempts = 0u; | 1290 const size_t kRetryAttempts = 0u; |
| 1297 scoped_ptr<HostResolver> host_resolver( | 1291 scoped_ptr<HostResolver> host_resolver( |
| 1298 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 1292 new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
| 1299 kRetryAttempts, NULL)); | 1293 kMaxJobs, kRetryAttempts, NULL)); |
| 1300 | 1294 |
| 1301 TestHostResolverObserver observer; | 1295 TestHostResolverObserver observer; |
| 1302 host_resolver->AddObserver(&observer); | 1296 host_resolver->AddObserver(&observer); |
| 1303 | 1297 |
| 1304 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1298 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1305 // requests we make will not complete. | 1299 // requests we make will not complete. |
| 1306 | 1300 |
| 1307 HostResolver::RequestInfo req[] = { | 1301 HostResolver::RequestInfo req[] = { |
| 1308 CreateResolverRequest("req0", LOW), | 1302 CreateResolverRequest("req0", LOW), |
| 1309 CreateResolverRequest("req1", MEDIUM), | 1303 CreateResolverRequest("req1", MEDIUM), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 | 1368 |
| 1375 // Try cancelling a request which has not been attached to a job yet. | 1369 // Try cancelling a request which has not been attached to a job yet. |
| 1376 TEST_F(HostResolverImplTest, CancelPendingRequest) { | 1370 TEST_F(HostResolverImplTest, CancelPendingRequest) { |
| 1377 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1371 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1378 new CapturingHostResolverProc(NULL)); | 1372 new CapturingHostResolverProc(NULL)); |
| 1379 | 1373 |
| 1380 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1374 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1381 const size_t kMaxJobs = 1u; | 1375 const size_t kMaxJobs = 1u; |
| 1382 const size_t kRetryAttempts = 0u; | 1376 const size_t kRetryAttempts = 0u; |
| 1383 scoped_ptr<HostResolver> host_resolver( | 1377 scoped_ptr<HostResolver> host_resolver( |
| 1384 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 1378 new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
| 1385 kRetryAttempts, NULL)); | 1379 kMaxJobs, kRetryAttempts, NULL)); |
| 1386 | 1380 |
| 1387 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1381 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1388 // requests we make will not complete. | 1382 // requests we make will not complete. |
| 1389 | 1383 |
| 1390 HostResolver::RequestInfo req[] = { | 1384 HostResolver::RequestInfo req[] = { |
| 1391 CreateResolverRequest("req0", LOWEST), | 1385 CreateResolverRequest("req0", LOWEST), |
| 1392 CreateResolverRequest("req1", HIGHEST), // Will cancel. | 1386 CreateResolverRequest("req1", HIGHEST), // Will cancel. |
| 1393 CreateResolverRequest("req2", MEDIUM), | 1387 CreateResolverRequest("req2", MEDIUM), |
| 1394 CreateResolverRequest("req3", LOW), | 1388 CreateResolverRequest("req3", LOW), |
| 1395 CreateResolverRequest("req4", HIGHEST), // Will cancel. | 1389 CreateResolverRequest("req4", HIGHEST), // Will cancel. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 | 1432 |
| 1439 // Test that when too many requests are enqueued, old ones start to be aborted. | 1433 // Test that when too many requests are enqueued, old ones start to be aborted. |
| 1440 TEST_F(HostResolverImplTest, QueueOverflow) { | 1434 TEST_F(HostResolverImplTest, QueueOverflow) { |
| 1441 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1435 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1442 new CapturingHostResolverProc(NULL)); | 1436 new CapturingHostResolverProc(NULL)); |
| 1443 | 1437 |
| 1444 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1438 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1445 const size_t kMaxOutstandingJobs = 1u; | 1439 const size_t kMaxOutstandingJobs = 1u; |
| 1446 const size_t kRetryAttempts = 0u; | 1440 const size_t kRetryAttempts = 0u; |
| 1447 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1441 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1448 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, kRetryAttempts, | 1442 resolver_proc, HostCache::CreateDefaultCache(), kMaxOutstandingJobs, |
| 1449 NULL)); | 1443 kRetryAttempts, NULL)); |
| 1450 | 1444 |
| 1451 // Only allow up to 3 requests to be enqueued at a time. | 1445 // Only allow up to 3 requests to be enqueued at a time. |
| 1452 const size_t kMaxPendingRequests = 3u; | 1446 const size_t kMaxPendingRequests = 3u; |
| 1453 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, | 1447 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
| 1454 kMaxOutstandingJobs, | 1448 kMaxOutstandingJobs, |
| 1455 kMaxPendingRequests); | 1449 kMaxPendingRequests); |
| 1456 | 1450 |
| 1457 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1451 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1458 // requests we make will not complete. | 1452 // requests we make will not complete. |
| 1459 | 1453 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 // Tests that after changing the default AddressFamily to IPV4, requests | 1512 // Tests that after changing the default AddressFamily to IPV4, requests |
| 1519 // with UNSPECIFIED address family map to IPV4. | 1513 // with UNSPECIFIED address family map to IPV4. |
| 1520 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { | 1514 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { |
| 1521 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1515 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1522 new CapturingHostResolverProc(new EchoingHostResolverProc)); | 1516 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| 1523 | 1517 |
| 1524 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1518 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1525 const size_t kMaxOutstandingJobs = 1u; | 1519 const size_t kMaxOutstandingJobs = 1u; |
| 1526 const size_t kRetryAttempts = 0u; | 1520 const size_t kRetryAttempts = 0u; |
| 1527 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1521 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1528 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, kRetryAttempts, | 1522 resolver_proc, HostCache::CreateDefaultCache(), kMaxOutstandingJobs, |
| 1529 NULL)); | 1523 kRetryAttempts, NULL)); |
| 1530 | 1524 |
| 1531 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1525 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1532 | 1526 |
| 1533 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1527 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1534 // requests we make will not complete. | 1528 // requests we make will not complete. |
| 1535 | 1529 |
| 1536 HostResolver::RequestInfo req[] = { | 1530 HostResolver::RequestInfo req[] = { |
| 1537 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1531 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1538 ADDRESS_FAMILY_UNSPECIFIED), | 1532 ADDRESS_FAMILY_UNSPECIFIED), |
| 1539 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), | 1533 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of | 1582 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of |
| 1589 // IPv4. | 1583 // IPv4. |
| 1590 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { | 1584 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { |
| 1591 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1585 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1592 new CapturingHostResolverProc(new EchoingHostResolverProc)); | 1586 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| 1593 | 1587 |
| 1594 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1588 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1595 const size_t kMaxOutstandingJobs = 1u; | 1589 const size_t kMaxOutstandingJobs = 1u; |
| 1596 const size_t kRetryAttempts = 0u; | 1590 const size_t kRetryAttempts = 0u; |
| 1597 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1591 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1598 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, kRetryAttempts, | 1592 resolver_proc, HostCache::CreateDefaultCache(), kMaxOutstandingJobs, |
| 1599 NULL)); | 1593 kRetryAttempts, NULL)); |
| 1600 | 1594 |
| 1601 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); | 1595 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); |
| 1602 | 1596 |
| 1603 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1597 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1604 // requests we make will not complete. | 1598 // requests we make will not complete. |
| 1605 | 1599 |
| 1606 HostResolver::RequestInfo req[] = { | 1600 HostResolver::RequestInfo req[] = { |
| 1607 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), | 1601 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), |
| 1608 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1602 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1609 ADDRESS_FAMILY_UNSPECIFIED), | 1603 ADDRESS_FAMILY_UNSPECIFIED), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); | 1648 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); |
| 1655 } | 1649 } |
| 1656 | 1650 |
| 1657 // This tests that the default address family is respected for synchronous | 1651 // This tests that the default address family is respected for synchronous |
| 1658 // resolutions. | 1652 // resolutions. |
| 1659 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { | 1653 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { |
| 1660 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1654 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1661 new CapturingHostResolverProc(new EchoingHostResolverProc)); | 1655 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| 1662 | 1656 |
| 1663 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1657 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1664 resolver_proc, CreateDefaultCache(), kMaxJobs, kMaxRetryAttempts, NULL)); | 1658 resolver_proc, HostCache::CreateDefaultCache(), kMaxJobs, |
| 1659 kMaxRetryAttempts, NULL)); |
| 1665 | 1660 |
| 1666 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1661 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1667 | 1662 |
| 1668 // Unblock the resolver thread so the requests can run. | 1663 // Unblock the resolver thread so the requests can run. |
| 1669 resolver_proc->Signal(); | 1664 resolver_proc->Signal(); |
| 1670 | 1665 |
| 1671 HostResolver::RequestInfo req[] = { | 1666 HostResolver::RequestInfo req[] = { |
| 1672 CreateResolverRequestForAddressFamily("b", MEDIUM, | 1667 CreateResolverRequestForAddressFamily("b", MEDIUM, |
| 1673 ADDRESS_FAMILY_UNSPECIFIED), | 1668 ADDRESS_FAMILY_UNSPECIFIED), |
| 1674 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), | 1669 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 // Total number of attempts would be 3 and we want the 3rd attempt to resolve | 1746 // Total number of attempts would be 3 and we want the 3rd attempt to resolve |
| 1752 // the host. First and second attempt will be forced to sleep until they get | 1747 // the host. First and second attempt will be forced to sleep until they get |
| 1753 // word that a resolution has completed. The 3rd resolution attempt will try | 1748 // word that a resolution has completed. The 3rd resolution attempt will try |
| 1754 // to get done ASAP, and won't sleep.. | 1749 // to get done ASAP, and won't sleep.. |
| 1755 int kAttemptNumberToResolve = 3; | 1750 int kAttemptNumberToResolve = 3; |
| 1756 int kTotalAttempts = 3; | 1751 int kTotalAttempts = 3; |
| 1757 | 1752 |
| 1758 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( | 1753 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( |
| 1759 new LookupAttemptHostResolverProc( | 1754 new LookupAttemptHostResolverProc( |
| 1760 NULL, kAttemptNumberToResolve, kTotalAttempts)); | 1755 NULL, kAttemptNumberToResolve, kTotalAttempts)); |
| 1761 HostCache* cache = CreateDefaultCache(); | 1756 HostCache* cache = HostCache::CreateDefaultCache(); |
| 1762 scoped_ptr<HostResolverImpl> host_resolver( | 1757 scoped_ptr<HostResolverImpl> host_resolver( |
| 1763 new HostResolverImpl(resolver_proc, cache, kMaxJobs, kMaxRetryAttempts, | 1758 new HostResolverImpl(resolver_proc, cache, kMaxJobs, kMaxRetryAttempts, |
| 1764 NULL)); | 1759 NULL)); |
| 1765 | 1760 |
| 1766 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so | 1761 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so |
| 1767 // that unit test runs faster. For example, this test finishes in 1.5 secs | 1762 // that unit test runs faster. For example, this test finishes in 1.5 secs |
| 1768 // (500ms * 3). | 1763 // (500ms * 3). |
| 1769 TimeDelta kUnresponsiveTime = TimeDelta::FromMilliseconds(500); | 1764 TimeDelta kUnresponsiveTime = TimeDelta::FromMilliseconds(500); |
| 1770 host_resolver->set_unresponsive_delay(kUnresponsiveTime); | 1765 host_resolver->set_unresponsive_delay(kUnresponsiveTime); |
| 1771 | 1766 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1783 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); | 1778 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); |
| 1784 MessageLoop::current()->RunAllPending(); | 1779 MessageLoop::current()->RunAllPending(); |
| 1785 | 1780 |
| 1786 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1781 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
| 1787 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1782 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
| 1788 } | 1783 } |
| 1789 | 1784 |
| 1790 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1785 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1791 | 1786 |
| 1792 } // namespace net | 1787 } // namespace net |
| OLD | NEW |