Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 HostResolverProc* resolver_proc) { | 44 HostResolverProc* resolver_proc) { |
| 45 return HostResolverImpl::ProcTaskParams(resolver_proc, | 45 return HostResolverImpl::ProcTaskParams(resolver_proc, |
| 46 kMaxRetryAttempts); | 46 kMaxRetryAttempts); |
| 47 } | 47 } |
| 48 | 48 |
| 49 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { | 49 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { |
| 50 return new HostResolverImpl( | 50 return new HostResolverImpl( |
| 51 HostCache::CreateDefaultCache(), | 51 HostCache::CreateDefaultCache(), |
| 52 DefaultLimits(), | 52 DefaultLimits(), |
| 53 DefaultParams(resolver_proc), | 53 DefaultParams(resolver_proc), |
| 54 scoped_ptr<DnsConfigService>(NULL), | |
| 54 NULL); | 55 NULL); |
| 55 } | 56 } |
| 56 | 57 |
| 57 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 58 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 58 HostResolverImpl* CreateSerialHostResolverImpl( | 59 HostResolverImpl* CreateSerialHostResolverImpl( |
| 59 HostResolverProc* resolver_proc) { | 60 HostResolverProc* resolver_proc) { |
| 60 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); | 61 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); |
| 61 params.max_retry_attempts = 0u; | 62 params.max_retry_attempts = 0u; |
| 62 | 63 |
| 63 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); | 64 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); |
| 64 | 65 |
| 65 return new HostResolverImpl(HostCache::CreateDefaultCache(), | 66 return new HostResolverImpl(HostCache::CreateDefaultCache(), |
| 66 limits, | 67 limits, |
| 67 params, | 68 params, |
| 69 scoped_ptr<DnsConfigService>(NULL), | |
| 68 NULL); | 70 NULL); |
| 69 } | 71 } |
| 70 | 72 |
| 71 // Helper to create a HostResolver::RequestInfo. | 73 // Helper to create a HostResolver::RequestInfo. |
| 72 HostResolver::RequestInfo CreateResolverRequest( | 74 HostResolver::RequestInfo CreateResolverRequest( |
| 73 const std::string& hostname, | 75 const std::string& hostname, |
| 74 RequestPriority priority) { | 76 RequestPriority priority) { |
| 75 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); | 77 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); |
| 76 info.set_priority(priority); | 78 info.set_priority(priority); |
| 77 return info; | 79 return info; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 } | 429 } |
| 428 | 430 |
| 429 TEST_F(HostResolverImplTest, FailedAsynchronousLookup) { | 431 TEST_F(HostResolverImplTest, FailedAsynchronousLookup) { |
| 430 AddressList addrlist; | 432 AddressList addrlist; |
| 431 const int kPortnum = 80; | 433 const int kPortnum = 80; |
| 432 | 434 |
| 433 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | 435 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
| 434 new RuleBasedHostResolverProc(NULL)); | 436 new RuleBasedHostResolverProc(NULL)); |
| 435 resolver_proc->AddSimulatedFailure("just.testing"); | 437 resolver_proc->AddSimulatedFailure("just.testing"); |
| 436 | 438 |
| 437 scoped_ptr<HostResolver> host_resolver( | 439 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); |
| 438 CreateHostResolverImpl(resolver_proc)); | |
| 439 | 440 |
| 440 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 441 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
| 441 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 442 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 442 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL, | 443 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL, |
| 443 log.bound()); | 444 log.bound()); |
| 444 EXPECT_EQ(ERR_IO_PENDING, err); | 445 EXPECT_EQ(ERR_IO_PENDING, err); |
| 445 | 446 |
| 446 CapturingNetLog::EntryList entries; | 447 CapturingNetLog::EntryList entries; |
| 447 log.GetEntries(&entries); | 448 log.GetEntries(&entries); |
| 448 | 449 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 467 } | 468 } |
| 468 | 469 |
| 469 // Using WaitingHostResolverProc you can simulate very long lookups. | 470 // Using WaitingHostResolverProc you can simulate very long lookups. |
| 470 class WaitingHostResolverProc : public HostResolverProc { | 471 class WaitingHostResolverProc : public HostResolverProc { |
| 471 public: | 472 public: |
| 472 explicit WaitingHostResolverProc(HostResolverProc* previous) | 473 explicit WaitingHostResolverProc(HostResolverProc* previous) |
| 473 : HostResolverProc(previous), | 474 : HostResolverProc(previous), |
| 474 is_waiting_(false, false), | 475 is_waiting_(false, false), |
| 475 is_signaled_(false, false) {} | 476 is_signaled_(false, false) {} |
| 476 | 477 |
| 478 // If |manual_reset| is true, once Signalled, it will let all Resolve calls to | |
| 479 // proceed. | |
|
mmenke
2012/02/21 16:34:24
nit: Remove "to"
| |
| 480 WaitingHostResolverProc(HostResolverProc* previous, bool manual_reset) | |
| 481 : HostResolverProc(previous), | |
| 482 is_waiting_(false, false), | |
| 483 is_signaled_(manual_reset, false) {} | |
|
mmenke
2012/02/21 16:34:24
nit: Fix indent
| |
| 484 | |
| 477 // Waits until a call to |Resolve| is blocked. It is recommended to always | 485 // Waits until a call to |Resolve| is blocked. It is recommended to always |
| 478 // |Wait| before |Signal|, and required if issuing a series of two or more | 486 // |Wait| before |Signal|, and required if issuing a series of two or more |
| 479 // calls to |Signal|, because |WaitableEvent| does not count the number of | 487 // calls to |Signal|, because |WaitableEvent| does not count the number of |
| 480 // signals. | 488 // signals. |
| 481 void Wait() { | 489 void Wait() { |
| 482 is_waiting_.Wait(); | 490 is_waiting_.Wait(); |
| 483 } | 491 } |
| 484 | 492 |
| 485 // Signals a waiting call to |Resolve|. | 493 // Signals a waiting call to |Resolve|. |
| 486 void Signal() { | 494 void Signal() { |
| 487 is_signaled_.Signal(); | 495 is_signaled_.Signal(); |
| 488 } | 496 } |
| 489 | 497 |
| 490 // HostResolverProc methods: | 498 // HostResolverProc methods: |
| 491 virtual int Resolve(const std::string& host, | 499 virtual int Resolve(const std::string& host, |
| 492 AddressFamily address_family, | 500 AddressFamily address_family, |
| 493 HostResolverFlags host_resolver_flags, | 501 HostResolverFlags host_resolver_flags, |
| 494 AddressList* addrlist, | 502 AddressList* addrlist, |
| 495 int* os_error) { | 503 int* os_error) { |
| 496 is_waiting_.Signal(); | 504 is_waiting_.Signal(); |
| 497 is_signaled_.Wait(); | 505 is_signaled_.Wait(); |
| 498 return ResolveUsingPrevious(host, address_family, host_resolver_flags, | 506 return ResolveUsingPrevious(host, address_family, host_resolver_flags, |
| 499 addrlist, os_error); | 507 addrlist, os_error); |
| 500 } | 508 } |
| 501 | 509 |
| 502 private: | 510 private: |
| 503 virtual ~WaitingHostResolverProc() {} | 511 virtual ~WaitingHostResolverProc() {} |
| 504 | |
| 505 base::WaitableEvent is_waiting_; | 512 base::WaitableEvent is_waiting_; |
| 506 base::WaitableEvent is_signaled_; | 513 base::WaitableEvent is_signaled_; |
| 507 }; | 514 }; |
| 508 | 515 |
| 509 TEST_F(HostResolverImplTest, AbortedAsynchronousLookup) { | 516 TEST_F(HostResolverImplTest, AbortedAsynchronousLookup) { |
| 510 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 517 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| 511 new WaitingHostResolverProc(NULL)); | 518 new WaitingHostResolverProc(NULL)); |
| 512 | 519 |
| 513 CapturingNetLog net_log(CapturingNetLog::kUnbounded); | 520 CapturingNetLog net_log(CapturingNetLog::kUnbounded); |
| 514 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 521 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 515 { | 522 { |
| 516 // This resolver will be destroyed while a lookup is running on WorkerPool. | 523 // This resolver will be destroyed while a lookup is running on WorkerPool. |
| 517 scoped_ptr<HostResolver> host_resolver( | 524 scoped_ptr<HostResolver> host_resolver( |
| 518 new HostResolverImpl(HostCache::CreateDefaultCache(), | 525 new HostResolverImpl(HostCache::CreateDefaultCache(), |
| 519 DefaultLimits(), | 526 DefaultLimits(), |
| 520 DefaultParams(resolver_proc), | 527 DefaultParams(resolver_proc), |
| 528 scoped_ptr<DnsConfigService>(NULL), | |
| 521 &net_log)); | 529 &net_log)); |
| 522 AddressList addrlist; | 530 AddressList addrlist; |
| 523 const int kPortnum = 80; | 531 const int kPortnum = 80; |
| 524 | 532 |
| 525 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 533 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
| 526 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL, | 534 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL, |
| 527 log.bound()); | 535 log.bound()); |
| 528 EXPECT_EQ(ERR_IO_PENDING, err); | 536 EXPECT_EQ(ERR_IO_PENDING, err); |
| 529 | 537 |
| 530 resolver_proc->Wait(); | 538 resolver_proc->Wait(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 546 | 554 |
| 547 int pos = ExpectLogContainsSomewhereAfter(net_log_entries, 0, | 555 int pos = ExpectLogContainsSomewhereAfter(net_log_entries, 0, |
| 548 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 556 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| 549 NetLog::PHASE_BEGIN); | 557 NetLog::PHASE_BEGIN); |
| 550 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 558 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 551 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 559 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 552 NetLog::PHASE_BEGIN); | 560 NetLog::PHASE_BEGIN); |
| 553 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 561 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 554 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | 562 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, |
| 555 NetLog::PHASE_BEGIN); | 563 NetLog::PHASE_BEGIN); |
| 556 // Both Request and ProcTask need to be cancelled. (The Job is "aborted".) | 564 |
| 557 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 565 // The Request needs to be cancelled. (The Job is "aborted".) |
| 558 NetLog::TYPE_CANCELLED, | 566 // Don't care about order in which Request, Job and ProcTask end. |
| 559 NetLog::PHASE_NONE); | |
| 560 // Don't care about order in which Request, Job and ProcTask end, or when the | |
| 561 // other one is cancelled. | |
| 562 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 567 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 563 NetLog::TYPE_CANCELLED, | 568 NetLog::TYPE_CANCELLED, |
| 564 NetLog::PHASE_NONE); | 569 NetLog::PHASE_NONE); |
| 565 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 570 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 571 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | |
| 572 NetLog::PHASE_END); | |
| 573 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | |
| 566 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 574 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| 567 NetLog::PHASE_END); | 575 NetLog::PHASE_END); |
| 568 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 576 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 569 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | |
| 570 NetLog::PHASE_END); | |
| 571 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | |
| 572 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 577 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 573 NetLog::PHASE_END); | 578 NetLog::PHASE_END); |
| 574 | 579 |
| 575 EXPECT_FALSE(callback_called_); | 580 EXPECT_FALSE(callback_called_); |
| 576 } | 581 } |
| 577 | 582 |
| 578 TEST_F(HostResolverImplTest, NumericIPv4Address) { | 583 TEST_F(HostResolverImplTest, NumericIPv4Address) { |
| 579 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. | 584 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. |
| 580 | 585 |
| 581 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | 586 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 | 971 |
| 967 TEST_F(HostResolverImplTest, StartWithinCallback) { | 972 TEST_F(HostResolverImplTest, StartWithinCallback) { |
| 968 // Use a capturing resolver_proc, since the verifier needs to know what calls | 973 // Use a capturing resolver_proc, since the verifier needs to know what calls |
| 969 // reached Resolver(). Also, the capturing resolver_proc is initially | 974 // reached Resolver(). Also, the capturing resolver_proc is initially |
| 970 // blocked. | 975 // blocked. |
| 971 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 976 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 972 new CapturingHostResolverProc(NULL)); | 977 new CapturingHostResolverProc(NULL)); |
| 973 | 978 |
| 974 // Turn off caching for this host resolver. | 979 // Turn off caching for this host resolver. |
| 975 scoped_ptr<HostResolver> host_resolver(new HostResolverImpl( | 980 scoped_ptr<HostResolver> host_resolver(new HostResolverImpl( |
| 976 NULL, DefaultLimits(), DefaultParams(resolver_proc), NULL)); | 981 NULL, |
| 982 DefaultLimits(), | |
| 983 DefaultParams(resolver_proc), | |
| 984 scoped_ptr<DnsConfigService>(NULL), | |
| 985 NULL)); | |
| 977 | 986 |
| 978 // The class will receive callbacks for when each resolve completes. It | 987 // The class will receive callbacks for when each resolve completes. It |
| 979 // checks that the right things happened. | 988 // checks that the right things happened. |
| 980 StartWithinCallbackVerifier verifier; | 989 StartWithinCallbackVerifier verifier; |
| 981 | 990 |
| 982 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is | 991 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is |
| 983 // blocked, these should all pile up until we signal it. | 992 // blocked, these should all pile up until we signal it. |
| 984 | 993 |
| 985 ResolveRequest req1(host_resolver.get(), "a", 80, &verifier); | 994 ResolveRequest req1(host_resolver.get(), "a", 80, &verifier); |
| 986 ResolveRequest req2(host_resolver.get(), "a", 81, &verifier); | 995 ResolveRequest req2(host_resolver.get(), "a", 81, &verifier); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1134 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 1143 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); |
| 1135 | 1144 |
| 1136 rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, | 1145 rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
| 1137 BoundNetLog()); | 1146 BoundNetLog()); |
| 1138 EXPECT_EQ(ERR_IO_PENDING, rv); | 1147 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1139 resolver_proc->Wait(); | 1148 resolver_proc->Wait(); |
| 1140 resolver_proc->Signal(); | 1149 resolver_proc->Signal(); |
| 1141 EXPECT_EQ(OK, callback.WaitForResult()); | 1150 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1142 } | 1151 } |
| 1143 | 1152 |
| 1144 class ResolveWithinCallback { | 1153 // Helper class used by AbortOnlyExistingRequestsOnIPAddressChange. |
| 1154 class StartWithinAbortedCallbackVerifier : public ResolveRequest::Delegate { | |
| 1145 public: | 1155 public: |
| 1146 explicit ResolveWithinCallback(const HostResolver::RequestInfo& info) | 1156 StartWithinAbortedCallbackVerifier(const std::string& next_hostname) |
| 1147 : info_(info) {} | 1157 : next_hostname_(next_hostname) {} |
| 1148 | 1158 |
| 1149 const CompletionCallback& callback() const { return callback_.callback(); } | 1159 virtual void OnCompleted(ResolveRequest* resolve) { |
|
mmenke
2012/02/21 16:34:24
nit: OVERRIDE
szym
2012/02/21 17:18:20
Done. Also on the other 10 cases.
| |
| 1150 | 1160 if (request_.get() == NULL) { |
| 1151 int WaitForResult() { | 1161 EXPECT_EQ(ERR_ABORTED, resolve->result()); |
| 1152 int result = callback_.WaitForResult(); | 1162 // Start new request for a different hostname to ensure that the order |
| 1153 // Ditch the WaitingHostResolverProc so that the subsequent request | 1163 // of jobs in HostResolverImpl is not stable. |
| 1154 // succeeds. | 1164 request_.reset(new ResolveRequest(resolve->resolver(), |
| 1155 host_resolver_.reset( | 1165 next_hostname_, |
| 1156 CreateHostResolverImpl(CreateCatchAllHostResolverProc())); | 1166 resolve->port(), |
| 1157 EXPECT_EQ(ERR_IO_PENDING, | 1167 this)); |
| 1158 host_resolver_->Resolve(info_, &addrlist_, | 1168 } else { |
| 1159 nested_callback_.callback(), NULL, | 1169 EXPECT_EQ(resolve, request_.get()); |
| 1160 BoundNetLog())); | 1170 callback_.callback().Run(resolve->result()); |
| 1161 return result; | 1171 } |
| 1162 } | 1172 } |
| 1163 | 1173 |
| 1164 int WaitForNestedResult() { | 1174 int WaitUntilDone() { |
| 1165 return nested_callback_.WaitForResult(); | 1175 return callback_.WaitForResult(); |
| 1166 } | 1176 } |
| 1167 | 1177 |
| 1168 private: | 1178 private: |
| 1169 const HostResolver::RequestInfo info_; | 1179 std::string next_hostname_; |
| 1170 AddressList addrlist_; | 1180 scoped_ptr<ResolveRequest> request_; |
| 1171 TestCompletionCallback callback_; | 1181 TestCompletionCallback callback_; |
| 1172 TestCompletionCallback nested_callback_; | 1182 DISALLOW_COPY_AND_ASSIGN(StartWithinAbortedCallbackVerifier); |
| 1173 scoped_ptr<HostResolver> host_resolver_; | |
| 1174 }; | 1183 }; |
| 1175 | 1184 |
| 1176 TEST_F(HostResolverImplTest, OnlyAbortExistingRequestsOnIPAddressChange) { | 1185 // Tests that a new Request made from the callback of a previously aborted one |
| 1186 // will not be aborted. | |
| 1187 TEST_F(HostResolverImplTest, AbortOnlyExistingRequestsOnIPAddressChange) { | |
| 1188 // Setting |manual_reset| to true so that Signal unblocks all calls. | |
| 1177 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 1189 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| 1178 new WaitingHostResolverProc(CreateCatchAllHostResolverProc())); | 1190 new WaitingHostResolverProc(CreateCatchAllHostResolverProc(), true)); |
| 1179 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); | 1191 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); |
| 1180 | 1192 |
| 1181 // Resolve "host1". | 1193 StartWithinAbortedCallbackVerifier verifier1("zzz"); |
| 1182 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1194 StartWithinAbortedCallbackVerifier verifier2("aaa"); |
| 1183 ResolveWithinCallback callback(info); | 1195 StartWithinAbortedCallbackVerifier verifier3("eee"); |
| 1184 AddressList addrlist; | |
| 1185 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, | |
| 1186 BoundNetLog()); | |
| 1187 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 1188 | 1196 |
| 1197 ResolveRequest req1(host_resolver.get(), "bbb", 40, &verifier1); | |
| 1198 ResolveRequest req2(host_resolver.get(), "eee", 80, &verifier2); | |
| 1199 ResolveRequest req3(host_resolver.get(), "ccc", 90, &verifier3); | |
| 1200 // The jobs start immediately. | |
| 1201 // Wait until at least one is blocked. | |
| 1189 resolver_proc->Wait(); | 1202 resolver_proc->Wait(); |
| 1190 // Triggering an IP address change. | 1203 // Trigger an IP address change. |
| 1191 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1204 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1192 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1205 // This should abort all running jobs. |
| 1193 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 1206 MessageLoop::current()->RunAllPending(); |
| 1194 resolver_proc->Signal(); // release the thread from WorkerPool for cleanup | 1207 EXPECT_EQ(ERR_ABORTED, req1.result()); |
| 1195 EXPECT_EQ(OK, callback.WaitForNestedResult()); | 1208 EXPECT_EQ(ERR_ABORTED, req2.result()); |
| 1209 EXPECT_EQ(ERR_ABORTED, req3.result()); | |
| 1210 // Unblock all calls to proc. | |
| 1211 resolver_proc->Signal(); | |
| 1212 // Run until the re-started requests finish. | |
| 1213 EXPECT_EQ(OK, verifier1.WaitUntilDone()); | |
| 1214 EXPECT_EQ(OK, verifier2.WaitUntilDone()); | |
| 1215 EXPECT_EQ(OK, verifier3.WaitUntilDone()); | |
| 1216 MessageLoop::current()->AssertIdle(); | |
| 1196 } | 1217 } |
| 1197 | 1218 |
| 1198 // Tests that when the maximum threads is set to 1, requests are dequeued | 1219 // Tests that when the maximum threads is set to 1, requests are dequeued |
| 1199 // in order of priority. | 1220 // in order of priority. |
| 1200 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1221 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
| 1201 scoped_refptr<CapturingHostResolverProc> resolver_proc( | 1222 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
| 1202 new CapturingHostResolverProc(NULL)); | 1223 new CapturingHostResolverProc(NULL)); |
| 1203 | 1224 |
| 1204 scoped_ptr<HostResolverImpl> host_resolver( | 1225 scoped_ptr<HostResolverImpl> host_resolver( |
| 1205 CreateSerialHostResolverImpl(resolver_proc)); | 1226 CreateSerialHostResolverImpl(resolver_proc)); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1568 // the host. First and second attempt will be forced to sleep until they get | 1589 // the host. First and second attempt will be forced to sleep until they get |
| 1569 // word that a resolution has completed. The 3rd resolution attempt will try | 1590 // word that a resolution has completed. The 3rd resolution attempt will try |
| 1570 // to get done ASAP, and won't sleep.. | 1591 // to get done ASAP, and won't sleep.. |
| 1571 int kAttemptNumberToResolve = 3; | 1592 int kAttemptNumberToResolve = 3; |
| 1572 int kTotalAttempts = 3; | 1593 int kTotalAttempts = 3; |
| 1573 | 1594 |
| 1574 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( | 1595 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( |
| 1575 new LookupAttemptHostResolverProc( | 1596 new LookupAttemptHostResolverProc( |
| 1576 NULL, kAttemptNumberToResolve, kTotalAttempts)); | 1597 NULL, kAttemptNumberToResolve, kTotalAttempts)); |
| 1577 | 1598 |
| 1578 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); | 1599 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc.get()); |
| 1579 | 1600 |
| 1580 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so | 1601 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so |
| 1581 // that unit test runs faster. For example, this test finishes in 1.5 secs | 1602 // that unit test runs faster. For example, this test finishes in 1.5 secs |
| 1582 // (500ms * 3). | 1603 // (500ms * 3). |
| 1583 params.unresponsive_delay = TimeDelta::FromMilliseconds(500); | 1604 params.unresponsive_delay = TimeDelta::FromMilliseconds(500); |
| 1584 | 1605 |
| 1585 scoped_ptr<HostResolverImpl> host_resolver( | 1606 scoped_ptr<HostResolverImpl> host_resolver( |
| 1586 new HostResolverImpl(HostCache::CreateDefaultCache(), | 1607 new HostResolverImpl(HostCache::CreateDefaultCache(), |
| 1587 DefaultLimits(), | 1608 DefaultLimits(), |
| 1588 params, | 1609 params, |
| 1610 scoped_ptr<DnsConfigService>(NULL), | |
| 1589 NULL)); | 1611 NULL)); |
| 1590 | 1612 |
| 1591 // Resolve "host1". | 1613 // Resolve "host1". |
| 1592 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1614 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
| 1593 TestCompletionCallback callback; | 1615 TestCompletionCallback callback; |
| 1594 AddressList addrlist; | 1616 AddressList addrlist; |
| 1595 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, | 1617 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
| 1596 BoundNetLog()); | 1618 BoundNetLog()); |
| 1597 EXPECT_EQ(ERR_IO_PENDING, rv); | 1619 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1598 | 1620 |
| 1599 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. | 1621 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. |
| 1600 EXPECT_EQ(-4, callback.WaitForResult()); | 1622 EXPECT_EQ(-4, callback.WaitForResult()); |
| 1601 | 1623 |
| 1602 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); | 1624 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); |
| 1603 MessageLoop::current()->RunAllPending(); | 1625 MessageLoop::current()->RunAllPending(); |
| 1604 | 1626 |
| 1605 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1627 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
| 1606 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1628 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
| 1607 } | 1629 } |
| 1608 | 1630 |
| 1609 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1631 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1610 | 1632 |
| 1611 } // namespace net | 1633 } // namespace net |
| OLD | NEW |