| 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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/synchronization/condition_variable.h" | 16 #include "base/synchronization/condition_variable.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/test/test_timeouts.h" |
| 18 #include "base/time.h" | 19 #include "base/time.h" |
| 19 #include "net/base/address_list.h" | 20 #include "net/base/address_list.h" |
| 20 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
| 21 #include "net/base/host_cache.h" | 22 #include "net/base/host_cache.h" |
| 22 #include "net/base/mock_host_resolver.h" | 23 #include "net/base/mock_host_resolver.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_log_unittest.h" | 25 #include "net/base/net_log_unittest.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 26 #include "net/base/sys_addrinfo.h" | 27 #include "net/base/sys_addrinfo.h" |
| 27 #include "net/base/test_completion_callback.h" | 28 #include "net/base/test_completion_callback.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 HostResolver::RequestInfo CreateResolverRequestForAddressFamily( | 84 HostResolver::RequestInfo CreateResolverRequestForAddressFamily( |
| 84 const std::string& hostname, | 85 const std::string& hostname, |
| 85 RequestPriority priority, | 86 RequestPriority priority, |
| 86 AddressFamily address_family) { | 87 AddressFamily address_family) { |
| 87 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); | 88 HostResolver::RequestInfo info(HostPortPair(hostname, 80)); |
| 88 info.set_priority(priority); | 89 info.set_priority(priority); |
| 89 info.set_address_family(address_family); | 90 info.set_address_family(address_family); |
| 90 return info; | 91 return info; |
| 91 } | 92 } |
| 92 | 93 |
| 94 // Using WaitingHostResolverProc you can simulate very long lookups. |
| 95 class WaitingHostResolverProc : public HostResolverProc { |
| 96 public: |
| 97 explicit WaitingHostResolverProc(HostResolverProc* previous) |
| 98 : HostResolverProc(previous), |
| 99 is_waiting_(false, false), |
| 100 is_signaled_(false, false) {} |
| 101 |
| 102 // Waits until a call to |Resolve| is blocked. It is recommended to always |
| 103 // |Wait| before |Signal|, and required if issuing a series of two or more |
| 104 // calls to |Signal|, because |WaitableEvent| does not count the number of |
| 105 // signals. |
| 106 void Wait() { |
| 107 is_waiting_.Wait(); |
| 108 } |
| 109 |
| 110 // Signals a waiting call to |Resolve|. |
| 111 void Signal() { |
| 112 is_signaled_.Signal(); |
| 113 } |
| 114 |
| 115 // HostResolverProc methods: |
| 116 virtual int Resolve(const std::string& host, |
| 117 AddressFamily address_family, |
| 118 HostResolverFlags host_resolver_flags, |
| 119 AddressList* addrlist, |
| 120 int* os_error) OVERRIDE { |
| 121 is_waiting_.Signal(); |
| 122 is_signaled_.Wait(); |
| 123 return ResolveUsingPrevious(host, address_family, host_resolver_flags, |
| 124 addrlist, os_error); |
| 125 } |
| 126 |
| 127 private: |
| 128 virtual ~WaitingHostResolverProc() {} |
| 129 base::WaitableEvent is_waiting_; |
| 130 base::WaitableEvent is_signaled_; |
| 131 }; |
| 132 |
| 93 // A variant of WaitingHostResolverProc that pushes each host mapped into a | 133 // A variant of WaitingHostResolverProc that pushes each host mapped into a |
| 94 // list. | 134 // list. |
| 95 // (and uses a manual-reset event rather than auto-reset). | 135 // (and uses a manual-reset event rather than auto-reset). |
| 96 class CapturingHostResolverProc : public HostResolverProc { | 136 class CapturingHostResolverProc : public HostResolverProc { |
| 97 public: | 137 public: |
| 98 struct CaptureEntry { | 138 struct CaptureEntry { |
| 99 CaptureEntry(const std::string& hostname, AddressFamily address_family) | 139 CaptureEntry(const std::string& hostname, AddressFamily address_family) |
| 100 : hostname(hostname), address_family(address_family) {} | 140 : hostname(hostname), address_family(address_family) {} |
| 101 std::string hostname; | 141 std::string hostname; |
| 102 AddressFamily address_family; | 142 AddressFamily address_family; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 176 } |
| 137 | 177 |
| 138 private: | 178 private: |
| 139 ~CapturingHostResolverProc() {} | 179 ~CapturingHostResolverProc() {} |
| 140 | 180 |
| 141 CaptureList capture_list_; | 181 CaptureList capture_list_; |
| 142 mutable base::Lock lock_; | 182 mutable base::Lock lock_; |
| 143 base::WaitableEvent event_; | 183 base::WaitableEvent event_; |
| 144 }; | 184 }; |
| 145 | 185 |
| 186 // A variant of WaitingHostResolverProc which waits for a specific number of |
| 187 // requests. |
| 188 class CountingHostResolverProc : public HostResolverProc { |
| 189 public: |
| 190 explicit CountingHostResolverProc(HostResolverProc* previous) |
| 191 : HostResolverProc(previous), |
| 192 num_requests_waiting_(0), |
| 193 num_slots_available_(0), |
| 194 requests_waiting_(&lock_), |
| 195 slots_available_(&lock_) {} |
| 196 |
| 197 // Waits until |count| calls to |Resolve| are blocked. Returns false when |
| 198 // timed out. |
| 199 bool WaitFor(unsigned count) { |
| 200 base::AutoLock lock(lock_); |
| 201 base::Time start_time = base::Time::Now(); |
| 202 while (num_requests_waiting_ < count) { |
| 203 requests_waiting_.TimedWait(TestTimeouts::action_timeout()); |
| 204 if (base::Time::Now() > start_time + TestTimeouts::action_timeout()) |
| 205 return false; |
| 206 } |
| 207 return true; |
| 208 } |
| 209 |
| 210 // Signals |count| waiting calls to |Resolve|. First come first served. |
| 211 void SignalMultiple(unsigned count) { |
| 212 base::AutoLock lock(lock_); |
| 213 num_slots_available_ += count; |
| 214 slots_available_.Broadcast(); |
| 215 } |
| 216 |
| 217 // Signals all waiting calls to |Resolve|. Beware of races. |
| 218 void SignalAll() { |
| 219 base::AutoLock lock(lock_); |
| 220 num_slots_available_ += num_requests_waiting_; |
| 221 slots_available_.Broadcast(); |
| 222 } |
| 223 |
| 224 // HostResolverProc methods: |
| 225 virtual int Resolve(const std::string& host, |
| 226 AddressFamily address_family, |
| 227 HostResolverFlags host_resolver_flags, |
| 228 AddressList* addrlist, |
| 229 int* os_error) OVERRIDE { |
| 230 { |
| 231 base::AutoLock lock(lock_); |
| 232 ++num_requests_waiting_; |
| 233 requests_waiting_.Broadcast(); |
| 234 while (!num_slots_available_) |
| 235 slots_available_.Wait(); |
| 236 --num_slots_available_; |
| 237 --num_requests_waiting_; |
| 238 } |
| 239 return ResolveUsingPrevious(host, address_family, host_resolver_flags, |
| 240 addrlist, os_error); |
| 241 } |
| 242 |
| 243 private: |
| 244 virtual ~CountingHostResolverProc() {} |
| 245 unsigned num_requests_waiting_; |
| 246 unsigned num_slots_available_; |
| 247 base::Lock lock_; |
| 248 base::ConditionVariable requests_waiting_; |
| 249 base::ConditionVariable slots_available_; |
| 250 }; |
| 251 |
| 146 // This resolver function creates an IPv4 address, whose numeral value | 252 // This resolver function creates an IPv4 address, whose numeral value |
| 147 // describes a hash of the requested hostname, and the value of the requested | 253 // describes a hash of the requested hostname, and the value of the requested |
| 148 // address_family. | 254 // address_family. |
| 149 // | 255 // |
| 150 // The resolved address for (hostname, address_family) will take the form: | 256 // The resolved address for (hostname, address_family) will take the form: |
| 151 // 192.x.y.z | 257 // 192.x.y.z |
| 152 // | 258 // |
| 153 // Where: | 259 // Where: |
| 154 // x = length of hostname | 260 // x = length of hostname |
| 155 // y = ASCII value of hostname[0] | 261 // y = ASCII value of hostname[0] |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 566 |
| 461 EXPECT_EQ(2u, entries.size()); | 567 EXPECT_EQ(2u, entries.size()); |
| 462 EXPECT_TRUE(LogContainsEndEvent( | 568 EXPECT_TRUE(LogContainsEndEvent( |
| 463 entries, 1, NetLog::TYPE_HOST_RESOLVER_IMPL)); | 569 entries, 1, NetLog::TYPE_HOST_RESOLVER_IMPL)); |
| 464 | 570 |
| 465 // Also test that the error is not cached! | 571 // Also test that the error is not cached! |
| 466 err = host_resolver->ResolveFromCache(info, &addrlist, log.bound()); | 572 err = host_resolver->ResolveFromCache(info, &addrlist, log.bound()); |
| 467 EXPECT_EQ(ERR_DNS_CACHE_MISS, err); | 573 EXPECT_EQ(ERR_DNS_CACHE_MISS, err); |
| 468 } | 574 } |
| 469 | 575 |
| 470 // Using WaitingHostResolverProc you can simulate very long lookups. | |
| 471 class WaitingHostResolverProc : public HostResolverProc { | |
| 472 public: | |
| 473 explicit WaitingHostResolverProc(HostResolverProc* previous) | |
| 474 : HostResolverProc(previous), | |
| 475 is_waiting_(false, false), | |
| 476 is_signaled_(false, false) {} | |
| 477 | |
| 478 // If |manual_reset| is true, once Signalled, it will let all Resolve calls | |
| 479 // proceed. | |
| 480 WaitingHostResolverProc(HostResolverProc* previous, bool manual_reset) | |
| 481 : HostResolverProc(previous), | |
| 482 is_waiting_(false, false), | |
| 483 is_signaled_(manual_reset, false) {} | |
| 484 | |
| 485 // Waits until a call to |Resolve| is blocked. It is recommended to always | |
| 486 // |Wait| before |Signal|, and required if issuing a series of two or more | |
| 487 // calls to |Signal|, because |WaitableEvent| does not count the number of | |
| 488 // signals. | |
| 489 void Wait() { | |
| 490 is_waiting_.Wait(); | |
| 491 } | |
| 492 | |
| 493 // Signals a waiting call to |Resolve|. | |
| 494 void Signal() { | |
| 495 is_signaled_.Signal(); | |
| 496 } | |
| 497 | |
| 498 // HostResolverProc methods: | |
| 499 virtual int Resolve(const std::string& host, | |
| 500 AddressFamily address_family, | |
| 501 HostResolverFlags host_resolver_flags, | |
| 502 AddressList* addrlist, | |
| 503 int* os_error) OVERRIDE { | |
| 504 is_waiting_.Signal(); | |
| 505 is_signaled_.Wait(); | |
| 506 return ResolveUsingPrevious(host, address_family, host_resolver_flags, | |
| 507 addrlist, os_error); | |
| 508 } | |
| 509 | |
| 510 private: | |
| 511 virtual ~WaitingHostResolverProc() {} | |
| 512 base::WaitableEvent is_waiting_; | |
| 513 base::WaitableEvent is_signaled_; | |
| 514 }; | |
| 515 | |
| 516 TEST_F(HostResolverImplTest, AbortedAsynchronousLookup) { | 576 TEST_F(HostResolverImplTest, AbortedAsynchronousLookup) { |
| 517 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 577 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
| 518 new WaitingHostResolverProc(NULL)); | 578 new WaitingHostResolverProc(NULL)); |
| 519 | 579 |
| 520 CapturingNetLog net_log(CapturingNetLog::kUnbounded); | 580 CapturingNetLog net_log(CapturingNetLog::kUnbounded); |
| 521 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 581 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 522 { | 582 { |
| 523 // This resolver will be destroyed while a lookup is running on WorkerPool. | 583 // This resolver will be destroyed while a lookup is running on WorkerPool. |
| 524 scoped_ptr<HostResolver> host_resolver( | 584 scoped_ptr<HostResolver> host_resolver( |
| 525 new HostResolverImpl(HostCache::CreateDefaultCache(), | 585 new HostResolverImpl(HostCache::CreateDefaultCache(), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 552 CapturingNetLog::EntryList net_log_entries; | 612 CapturingNetLog::EntryList net_log_entries; |
| 553 net_log.GetEntries(&net_log_entries); | 613 net_log.GetEntries(&net_log_entries); |
| 554 | 614 |
| 555 int pos = ExpectLogContainsSomewhereAfter(net_log_entries, 0, | 615 int pos = ExpectLogContainsSomewhereAfter(net_log_entries, 0, |
| 556 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 616 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| 557 NetLog::PHASE_BEGIN); | 617 NetLog::PHASE_BEGIN); |
| 558 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 618 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 559 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 619 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 560 NetLog::PHASE_BEGIN); | 620 NetLog::PHASE_BEGIN); |
| 561 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 621 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 562 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | 622 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, |
| 563 NetLog::PHASE_BEGIN); | 623 NetLog::PHASE_BEGIN); |
| 564 | 624 |
| 565 // The Request needs to be cancelled. (The Job is "aborted".) | 625 // The Request needs to be cancelled. (The Job is "aborted".) |
| 566 // Don't care about order in which Request, Job and ProcTask end. | 626 // Don't care about order in which Request, Job and ProcTask end. |
| 567 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 627 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 568 NetLog::TYPE_CANCELLED, | 628 NetLog::TYPE_CANCELLED, |
| 569 NetLog::PHASE_NONE); | 629 NetLog::PHASE_NONE); |
| 570 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 630 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| 571 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | 631 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, |
| 572 NetLog::PHASE_END); | 632 NetLog::PHASE_END); |
| 573 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, | 633 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 req3.Cancel(); | 861 req3.Cancel(); |
| 802 req5.Cancel(); | 862 req5.Cancel(); |
| 803 | 863 |
| 804 // Ready, Set, GO!!! | 864 // Ready, Set, GO!!! |
| 805 resolver_proc->Signal(); | 865 resolver_proc->Signal(); |
| 806 | 866 |
| 807 // |verifier| will send quit message once all the requests have finished. | 867 // |verifier| will send quit message once all the requests have finished. |
| 808 MessageLoop::current()->Run(); | 868 MessageLoop::current()->Run(); |
| 809 } | 869 } |
| 810 | 870 |
| 871 // Helper class used by HostResolverImplTest.CanceledRequestsReleaseJobSlots. |
| 872 class CountingDelegate : public ResolveRequest::Delegate { |
| 873 public: |
| 874 CountingDelegate() : num_completions_(0) {} |
| 875 |
| 876 virtual void OnCompleted(ResolveRequest* resolve) OVERRIDE { |
| 877 ++num_completions_; |
| 878 MessageLoop::current()->Quit(); |
| 879 } |
| 880 |
| 881 unsigned num_completions() const { return num_completions_; } |
| 882 |
| 883 private: |
| 884 unsigned num_completions_; |
| 885 }; |
| 886 |
| 887 TEST_F(HostResolverImplTest, CanceledRequestsReleaseJobSlots) { |
| 888 scoped_refptr<CountingHostResolverProc> resolver_proc( |
| 889 new CountingHostResolverProc(NULL)); |
| 890 |
| 891 scoped_ptr<HostResolver> host_resolver( |
| 892 CreateHostResolverImpl(resolver_proc)); |
| 893 |
| 894 CountingDelegate delegate; |
| 895 std::vector<ResolveRequest*> requests; |
| 896 |
| 897 // Fill up the dispatcher and queue. |
| 898 for (unsigned i = 0; i < kMaxJobs + 1; ++i) { |
| 899 std::string hostname = "a_"; |
| 900 hostname[1] = 'a' + i; |
| 901 requests.push_back(new ResolveRequest(host_resolver.get(), hostname, 80, |
| 902 &delegate)); |
| 903 requests.push_back(new ResolveRequest(host_resolver.get(), hostname, 81, |
| 904 &delegate)); |
| 905 } |
| 906 |
| 907 EXPECT_TRUE(resolver_proc->WaitFor(kMaxJobs)); |
| 908 |
| 909 // Cancel all but last two. |
| 910 for (unsigned i = 0; i < requests.size() - 2; ++i) { |
| 911 requests[i]->Cancel(); |
| 912 } |
| 913 |
| 914 EXPECT_TRUE(resolver_proc->WaitFor(kMaxJobs + 1)); |
| 915 EXPECT_EQ(0u, delegate.num_completions()); |
| 916 |
| 917 resolver_proc->SignalAll(); |
| 918 |
| 919 while (delegate.num_completions() < 2) |
| 920 MessageLoop::current()->Run(); |
| 921 |
| 922 MessageLoop::current()->AssertIdle(); |
| 923 } |
| 924 |
| 811 // Helper class used by HostResolverImplTest.CancelWithinCallback. | 925 // Helper class used by HostResolverImplTest.CancelWithinCallback. |
| 812 class CancelWithinCallbackVerifier : public ResolveRequest::Delegate { | 926 class CancelWithinCallbackVerifier : public ResolveRequest::Delegate { |
| 813 public: | 927 public: |
| 814 CancelWithinCallbackVerifier() | 928 CancelWithinCallbackVerifier() |
| 815 : req_to_cancel1_(NULL), req_to_cancel2_(NULL), num_completions_(0) { | 929 : req_to_cancel1_(NULL), req_to_cancel2_(NULL), num_completions_(0) { |
| 816 } | 930 } |
| 817 | 931 |
| 818 virtual void OnCompleted(ResolveRequest* resolve) OVERRIDE { | 932 virtual void OnCompleted(ResolveRequest* resolve) OVERRIDE { |
| 819 num_completions_++; | 933 num_completions_++; |
| 820 | 934 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 private: | 1292 private: |
| 1179 std::string next_hostname_; | 1293 std::string next_hostname_; |
| 1180 scoped_ptr<ResolveRequest> request_; | 1294 scoped_ptr<ResolveRequest> request_; |
| 1181 TestCompletionCallback callback_; | 1295 TestCompletionCallback callback_; |
| 1182 DISALLOW_COPY_AND_ASSIGN(StartWithinAbortedCallbackVerifier); | 1296 DISALLOW_COPY_AND_ASSIGN(StartWithinAbortedCallbackVerifier); |
| 1183 }; | 1297 }; |
| 1184 | 1298 |
| 1185 // Tests that a new Request made from the callback of a previously aborted one | 1299 // Tests that a new Request made from the callback of a previously aborted one |
| 1186 // will not be aborted. | 1300 // will not be aborted. |
| 1187 TEST_F(HostResolverImplTest, AbortOnlyExistingRequestsOnIPAddressChange) { | 1301 TEST_F(HostResolverImplTest, AbortOnlyExistingRequestsOnIPAddressChange) { |
| 1188 // Setting |manual_reset| to true so that Signal unblocks all calls. | 1302 scoped_refptr<CountingHostResolverProc> resolver_proc( |
| 1189 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 1303 new CountingHostResolverProc(CreateCatchAllHostResolverProc())); |
| 1190 new WaitingHostResolverProc(CreateCatchAllHostResolverProc(), true)); | |
| 1191 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); | 1304 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); |
| 1192 | 1305 |
| 1193 StartWithinAbortedCallbackVerifier verifier1("zzz"); | 1306 StartWithinAbortedCallbackVerifier verifier1("zzz"); |
| 1194 StartWithinAbortedCallbackVerifier verifier2("aaa"); | 1307 StartWithinAbortedCallbackVerifier verifier2("aaa"); |
| 1195 StartWithinAbortedCallbackVerifier verifier3("eee"); | 1308 StartWithinAbortedCallbackVerifier verifier3("eee"); |
| 1196 | 1309 |
| 1197 ResolveRequest req1(host_resolver.get(), "bbb", 40, &verifier1); | 1310 ResolveRequest req1(host_resolver.get(), "bbb", 40, &verifier1); |
| 1198 ResolveRequest req2(host_resolver.get(), "eee", 80, &verifier2); | 1311 ResolveRequest req2(host_resolver.get(), "eee", 80, &verifier2); |
| 1199 ResolveRequest req3(host_resolver.get(), "ccc", 90, &verifier3); | 1312 ResolveRequest req3(host_resolver.get(), "ccc", 90, &verifier3); |
| 1200 // The jobs start immediately. | 1313 // The jobs start immediately. |
| 1201 // Wait until at least one is blocked. | 1314 // Wait until all are blocked; |
| 1202 resolver_proc->Wait(); | 1315 resolver_proc->WaitFor(3u); |
| 1203 // Trigger an IP address change. | 1316 // Trigger an IP address change. |
| 1204 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1317 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1205 // This should abort all running jobs. | 1318 // This should abort all running jobs. |
| 1206 MessageLoop::current()->RunAllPending(); | 1319 MessageLoop::current()->RunAllPending(); |
| 1207 EXPECT_EQ(ERR_ABORTED, req1.result()); | 1320 EXPECT_EQ(ERR_ABORTED, req1.result()); |
| 1208 EXPECT_EQ(ERR_ABORTED, req2.result()); | 1321 EXPECT_EQ(ERR_ABORTED, req2.result()); |
| 1209 EXPECT_EQ(ERR_ABORTED, req3.result()); | 1322 EXPECT_EQ(ERR_ABORTED, req3.result()); |
| 1210 // Unblock all calls to proc. | 1323 // Unblock all calls to proc. |
| 1211 resolver_proc->Signal(); | 1324 resolver_proc->SignalMultiple(6u); |
| 1212 // Run until the re-started requests finish. | 1325 // Run until the re-started requests finish. |
| 1213 EXPECT_EQ(OK, verifier1.WaitUntilDone()); | 1326 EXPECT_EQ(OK, verifier1.WaitUntilDone()); |
| 1214 EXPECT_EQ(OK, verifier2.WaitUntilDone()); | 1327 EXPECT_EQ(OK, verifier2.WaitUntilDone()); |
| 1215 EXPECT_EQ(OK, verifier3.WaitUntilDone()); | 1328 EXPECT_EQ(OK, verifier3.WaitUntilDone()); |
| 1216 MessageLoop::current()->AssertIdle(); | 1329 MessageLoop::current()->AssertIdle(); |
| 1217 } | 1330 } |
| 1218 | 1331 |
| 1219 // Tests that when the maximum threads is set to 1, requests are dequeued | 1332 // Tests that when the maximum threads is set to 1, requests are dequeued |
| 1220 // in order of priority. | 1333 // in order of priority. |
| 1221 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1334 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); | 1737 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); |
| 1625 MessageLoop::current()->RunAllPending(); | 1738 MessageLoop::current()->RunAllPending(); |
| 1626 | 1739 |
| 1627 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1740 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
| 1628 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1741 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
| 1629 } | 1742 } |
| 1630 | 1743 |
| 1631 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1744 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1632 | 1745 |
| 1633 } // namespace net | 1746 } // namespace net |
| OLD | NEW |