Chromium Code Reviews| Index: net/base/host_resolver_impl_unittest.cc |
| diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc |
| index 23c3325654f95aa666b7a01d93dcdd041ace93a0..61c6d98cd962d455f48dedd67cf75b05a7ebb205 100644 |
| --- a/net/base/host_resolver_impl_unittest.cc |
| +++ b/net/base/host_resolver_impl_unittest.cc |
| @@ -27,10 +27,6 @@ |
| #include "net/base/test_completion_callback.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -// TODO(eroman): |
| -// - Test mixing async with sync (in particular how does sync update the |
| -// cache while an async is already pending). |
| - |
| namespace net { |
| using base::TimeDelta; |
| @@ -39,9 +35,37 @@ using base::TimeTicks; |
| static const size_t kMaxJobs = 10u; |
| static const size_t kMaxRetryAttempts = 4u; |
| +PrioritizedDispatcher::Limits DefaultLimits() { |
| + PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, kMaxJobs); |
| + return limits; |
| +} |
| + |
| +HostResolverImpl::ProcTaskParams DefaultParams( |
| + HostResolverProc* resolver_proc) { |
| + return HostResolverImpl::ProcTaskParams(resolver_proc, |
| + kMaxRetryAttempts); |
|
mmenke
2012/01/26 16:54:10
nit: Fix indent.
|
| +} |
| + |
| HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { |
| - return new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
| - kMaxJobs, kMaxRetryAttempts, NULL); |
| + return new HostResolverImpl( |
| + HostCache::CreateDefaultCache(), |
| + DefaultLimits(), |
| + DefaultParams(resolver_proc), |
| + NULL); |
| +} |
| + |
| +// This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| +HostResolverImpl* CreateSerialHostResolverImpl( |
| + HostResolverProc* resolver_proc) { |
| + HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); |
| + params.max_retry_attempts = 0u; |
| + |
| + PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); |
| + |
| + return new HostResolverImpl(HostCache::CreateDefaultCache(), |
| + limits, |
| + params, |
| + NULL); |
| } |
| // Helper to create a HostResolver::RequestInfo. |
| @@ -451,10 +475,9 @@ TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { |
| CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| { |
| scoped_ptr<HostResolver> host_resolver( |
| - new HostResolverImpl(resolver_proc, |
| - HostCache::CreateDefaultCache(), |
| - kMaxJobs, |
| - kMaxRetryAttempts, |
| + new HostResolverImpl(HostCache::CreateDefaultCache(), |
| + DefaultLimits(), |
| + DefaultParams(resolver_proc), |
| &net_log)); |
| AddressList addrlist; |
| const int kPortnum = 80; |
| @@ -902,9 +925,8 @@ TEST_F(HostResolverImplTest, StartWithinCallback) { |
| new CapturingHostResolverProc(NULL)); |
| // Turn off caching for this host resolver. |
| - scoped_ptr<HostResolver> host_resolver( |
| - new HostResolverImpl(resolver_proc, NULL, kMaxJobs, kMaxRetryAttempts, |
| - NULL)); |
| + scoped_ptr<HostResolver> host_resolver(new HostResolverImpl( |
| + NULL, DefaultLimits(), DefaultParams(resolver_proc), NULL)); |
| // The class will receive callbacks for when each resolve completes. It |
| // checks that the right things happened. |
| @@ -984,8 +1006,7 @@ TEST_F(HostResolverImplTest, BypassCache) { |
| // Test that IP address changes flush the cache. |
| TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
| scoped_ptr<HostResolver> host_resolver( |
| - new HostResolverImpl(NULL, HostCache::CreateDefaultCache(), kMaxJobs, |
| - kMaxRetryAttempts, NULL)); |
| + CreateHostResolverImpl(NULL)); |
| AddressList addrlist; |
| @@ -1043,15 +1064,9 @@ TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
| TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { |
| scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| new WaitingHostResolverProc(CreateCatchAllHostResolverProc())); |
| - scoped_ptr<HostResolverImpl> host_resolver( |
| - new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
| - kMaxJobs, kMaxRetryAttempts, NULL)); |
| - const size_t kMaxOutstandingJobs = 1u; |
| - const size_t kMaxPendingRequests = 1000000u; // not relevant. |
| - host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
| - kMaxOutstandingJobs, |
| - kMaxPendingRequests); |
| + scoped_ptr<HostResolverImpl> host_resolver( |
| + CreateSerialHostResolverImpl(resolver_proc)); |
| // Resolve "host1". |
| HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
| @@ -1139,12 +1154,8 @@ TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
| scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| new CapturingHostResolverProc(NULL)); |
| - // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| - size_t kMaxJobs = 1u; |
| - const size_t kRetryAttempts = 0u; |
| - scoped_ptr<HostResolver> host_resolver( |
| - new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
| - kMaxJobs, kRetryAttempts, NULL)); |
| + scoped_ptr<HostResolverImpl> host_resolver( |
| + CreateSerialHostResolverImpl(resolver_proc)); |
| // Note that at this point the CapturingHostResolverProc is blocked, so any |
| // requests we make will not complete. |
| @@ -1201,12 +1212,8 @@ TEST_F(HostResolverImplTest, CancelPendingRequest) { |
| scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| new CapturingHostResolverProc(NULL)); |
| - // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| - const size_t kMaxJobs = 1u; |
| - const size_t kRetryAttempts = 0u; |
| - scoped_ptr<HostResolver> host_resolver( |
| - new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
| - kMaxJobs, kRetryAttempts, NULL)); |
| + scoped_ptr<HostResolverImpl> host_resolver( |
| + CreateSerialHostResolverImpl(resolver_proc)); |
| // Note that at this point the CapturingHostResolverProc is blocked, so any |
| // requests we make will not complete. |
| @@ -1216,8 +1223,8 @@ TEST_F(HostResolverImplTest, CancelPendingRequest) { |
| CreateResolverRequest("req1", HIGHEST), // Will cancel. |
| CreateResolverRequest("req2", MEDIUM), |
| CreateResolverRequest("req3", LOW), |
| - CreateResolverRequest("req4", HIGHEST), // Will cancel. |
| - CreateResolverRequest("req5", LOWEST), // Will cancel. |
| + CreateResolverRequest("req4", HIGHEST), // Will cancel. |
| + CreateResolverRequest("req5", LOWEST), // Will cancel. |
| CreateResolverRequest("req6", MEDIUM), |
| }; |
| @@ -1266,18 +1273,12 @@ TEST_F(HostResolverImplTest, QueueOverflow) { |
| scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| new CapturingHostResolverProc(NULL)); |
| - // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| - const size_t kMaxOutstandingJobs = 1u; |
| - const size_t kRetryAttempts = 0u; |
| - scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| - resolver_proc, HostCache::CreateDefaultCache(), kMaxOutstandingJobs, |
| - kRetryAttempts, NULL)); |
| - |
| - // Only allow up to 3 requests to be enqueued at a time. |
| - const size_t kMaxPendingRequests = 3u; |
| - host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
| - kMaxOutstandingJobs, |
| - kMaxPendingRequests); |
| + scoped_ptr<HostResolverImpl> host_resolver( |
| + CreateSerialHostResolverImpl(resolver_proc)); |
| + |
| + // Allow only 3 queued jobs. |
| + const size_t kMaxPendingJobs = 3u; |
| + host_resolver->SetMaxQueuedJobs(kMaxPendingJobs); |
| // Note that at this point the CapturingHostResolverProc is blocked, so any |
| // requests we make will not complete. |
| @@ -1348,11 +1349,8 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { |
| new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| - const size_t kMaxOutstandingJobs = 1u; |
| - const size_t kRetryAttempts = 0u; |
| - scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| - resolver_proc, HostCache::CreateDefaultCache(), kMaxOutstandingJobs, |
| - kRetryAttempts, NULL)); |
| + scoped_ptr<HostResolverImpl> host_resolver( |
| + CreateSerialHostResolverImpl(resolver_proc)); |
| host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| @@ -1418,12 +1416,8 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { |
| scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| new CapturingHostResolverProc(new EchoingHostResolverProc)); |
| - // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| - const size_t kMaxOutstandingJobs = 1u; |
| - const size_t kRetryAttempts = 0u; |
| - scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| - resolver_proc, HostCache::CreateDefaultCache(), kMaxOutstandingJobs, |
| - kRetryAttempts, NULL)); |
| + scoped_ptr<HostResolverImpl> host_resolver( |
| + CreateSerialHostResolverImpl(resolver_proc)); |
| host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); |
| @@ -1533,16 +1527,19 @@ TEST_F(HostResolverImplTest, MultipleAttempts) { |
| scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( |
| new LookupAttemptHostResolverProc( |
| NULL, kAttemptNumberToResolve, kTotalAttempts)); |
| - HostCache* cache = HostCache::CreateDefaultCache(); |
| - scoped_ptr<HostResolverImpl> host_resolver( |
| - new HostResolverImpl(resolver_proc, cache, kMaxJobs, kMaxRetryAttempts, |
| - NULL)); |
| + |
| + HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); |
| // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so |
| // that unit test runs faster. For example, this test finishes in 1.5 secs |
| // (500ms * 3). |
| - TimeDelta kUnresponsiveTime = TimeDelta::FromMilliseconds(500); |
| - host_resolver->set_unresponsive_delay(kUnresponsiveTime); |
| + params.unresponsive_delay = TimeDelta::FromMilliseconds(500); |
| + |
| + scoped_ptr<HostResolverImpl> host_resolver( |
| + new HostResolverImpl(HostCache::CreateDefaultCache(), |
| + DefaultLimits(), |
| + params, |
| + NULL)); |
| // Resolve "host1". |
| HostResolver::RequestInfo info(HostPortPair("host1", 70)); |