| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <time.h> | 5 #include <time.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 void WaitForResolution(DnsMaster* master, const NameList& hosts) { | 77 void WaitForResolution(DnsMaster* master, const NameList& hosts) { |
| 78 HelperTimer* timer = new HelperTimer(); | 78 HelperTimer* timer = new HelperTimer(); |
| 79 timer->Start(TimeDelta::FromMilliseconds(100), | 79 timer->Start(TimeDelta::FromMilliseconds(100), |
| 80 new WaitForResolutionHelper(master, hosts, timer), | 80 new WaitForResolutionHelper(master, hosts, timer), |
| 81 &WaitForResolutionHelper::Run); | 81 &WaitForResolutionHelper::Run); |
| 82 MessageLoop::current()->Run(); | 82 MessageLoop::current()->Run(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 scoped_refptr<net::RuleBasedHostMapper> mapper_; |
| 86 |
| 85 private: | 87 private: |
| 86 MessageLoop loop; | 88 MessageLoop loop; |
| 87 scoped_refptr<net::RuleBasedHostMapper> mapper_; | |
| 88 net::ScopedHostMapper scoped_mapper_; | 89 net::ScopedHostMapper scoped_mapper_; |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 //------------------------------------------------------------------------------ | 92 //------------------------------------------------------------------------------ |
| 92 // Provide a function to create unique (nonexistant) domains at *every* call. | 93 // Provide a function to create unique (nonexistant) domains at *every* call. |
| 93 //------------------------------------------------------------------------------ | 94 //------------------------------------------------------------------------------ |
| 94 static std::string GetNonexistantDomain() { | 95 static std::string GetNonexistantDomain() { |
| 95 static std::string postfix = ".google.com"; | 96 static std::string postfix = ".google.com"; |
| 96 static std::string prefix = "www."; | 97 static std::string prefix = "www."; |
| 97 static std::string mid = "datecount"; | 98 static std::string mid = "datecount"; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 114 resolver.Resolve(hostname, 80, &addresses, NULL); | 115 resolver.Resolve(hostname, 80, &addresses, NULL); |
| 115 | 116 |
| 116 return Time::Now() - start; | 117 return Time::Now() - start; |
| 117 } | 118 } |
| 118 | 119 |
| 119 //------------------------------------------------------------------------------ | 120 //------------------------------------------------------------------------------ |
| 120 | 121 |
| 121 // First test to be sure the OS is caching lookups, which is the whole premise | 122 // First test to be sure the OS is caching lookups, which is the whole premise |
| 122 // of DNS prefetching. | 123 // of DNS prefetching. |
| 123 TEST_F(DnsMasterTest, OsCachesLookupsTest) { | 124 TEST_F(DnsMasterTest, OsCachesLookupsTest) { |
| 125 mapper_->AllowDirectLookup("*.google.com"); |
| 126 |
| 124 const Time start = Time::Now(); | 127 const Time start = Time::Now(); |
| 125 int all_lookups = 0; | 128 int all_lookups = 0; |
| 126 int lookups_with_improvement = 0; | 129 int lookups_with_improvement = 0; |
| 127 // This test can be really flaky on Linux. It should run in much shorter time, | 130 // This test can be really flaky on Linux. It should run in much shorter time, |
| 128 // but sometimes it won't and we don't like bogus failures. | 131 // but sometimes it won't and we don't like bogus failures. |
| 129 while (Time::Now() - start < TimeDelta::FromMinutes(1)) { | 132 while (Time::Now() - start < TimeDelta::FromMinutes(1)) { |
| 130 std::string badname; | 133 std::string badname; |
| 131 badname = GetNonexistantDomain(); | 134 badname = GetNonexistantDomain(); |
| 132 | 135 |
| 133 TimeDelta duration = BlockingDnsLookup(badname); | 136 TimeDelta duration = BlockingDnsLookup(badname); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 269 |
| 267 EXPECT_GT(testing_master.peak_pending_lookups(), names.size() / 2); | 270 EXPECT_GT(testing_master.peak_pending_lookups(), names.size() / 2); |
| 268 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); | 271 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); |
| 269 EXPECT_LE(testing_master.peak_pending_lookups(), | 272 EXPECT_LE(testing_master.peak_pending_lookups(), |
| 270 DnsMaster::kMaxConcurrentLookups); | 273 DnsMaster::kMaxConcurrentLookups); |
| 271 | 274 |
| 272 testing_master.Shutdown(); | 275 testing_master.Shutdown(); |
| 273 } | 276 } |
| 274 | 277 |
| 275 TEST_F(DnsMasterTest, ConcurrentLookupTest) { | 278 TEST_F(DnsMasterTest, ConcurrentLookupTest) { |
| 279 mapper_->AddSimulatedFailure("*.notfound"); |
| 280 |
| 276 DnsMaster testing_master; | 281 DnsMaster testing_master; |
| 277 | 282 |
| 278 std::string goog("www.google.com"), | 283 std::string goog("www.google.com"), |
| 279 goog2("gmail.google.com.com"), | 284 goog2("gmail.google.com.com"), |
| 280 goog3("mail.google.com"), | 285 goog3("mail.google.com"), |
| 281 goog4("gmail.com"); | 286 goog4("gmail.com"); |
| 282 std::string bad1(GetNonexistantDomain()), | 287 std::string bad1("bad1.notfound"), |
| 283 bad2(GetNonexistantDomain()); | 288 bad2("bad2.notfound"); |
| 284 | 289 |
| 285 NameList names; | 290 NameList names; |
| 286 names.insert(names.end(), goog); | 291 names.insert(names.end(), goog); |
| 287 names.insert(names.end(), goog3); | 292 names.insert(names.end(), goog3); |
| 288 names.insert(names.end(), bad1); | 293 names.insert(names.end(), bad1); |
| 289 names.insert(names.end(), goog2); | 294 names.insert(names.end(), goog2); |
| 290 names.insert(names.end(), bad2); | 295 names.insert(names.end(), bad2); |
| 291 names.insert(names.end(), goog4); | 296 names.insert(names.end(), goog4); |
| 292 names.insert(names.end(), goog); | 297 names.insert(names.end(), goog); |
| 293 | 298 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 317 | 322 |
| 318 EXPECT_GT(testing_master.peak_pending_lookups(), names.size() / 2); | 323 EXPECT_GT(testing_master.peak_pending_lookups(), names.size() / 2); |
| 319 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); | 324 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); |
| 320 EXPECT_LE(testing_master.peak_pending_lookups(), | 325 EXPECT_LE(testing_master.peak_pending_lookups(), |
| 321 DnsMaster::kMaxConcurrentLookups); | 326 DnsMaster::kMaxConcurrentLookups); |
| 322 | 327 |
| 323 testing_master.Shutdown(); | 328 testing_master.Shutdown(); |
| 324 } | 329 } |
| 325 | 330 |
| 326 TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) { | 331 TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) { |
| 332 mapper_->AddSimulatedFailure("*.notfound"); |
| 333 |
| 327 DnsMaster testing_master; | 334 DnsMaster testing_master; |
| 328 | 335 |
| 329 NameList names; | 336 NameList names; |
| 330 for (int i = 0; i < 100; i++) | 337 for (int i = 0; i < 100; i++) |
| 331 names.push_back(GetNonexistantDomain()); | 338 names.push_back("host" + IntToString(i) + ".notfound"); |
| 332 | 339 |
| 333 // Try to flood the master with many concurrent requests. | 340 // Try to flood the master with many concurrent requests. |
| 334 for (int i = 0; i < 10; i++) | 341 for (int i = 0; i < 10; i++) |
| 335 testing_master.ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 342 testing_master.ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
| 336 | 343 |
| 337 WaitForResolution(&testing_master, names); | 344 WaitForResolution(&testing_master, names); |
| 338 | 345 |
| 339 MessageLoop::current()->RunAllPending(); | 346 MessageLoop::current()->RunAllPending(); |
| 340 | 347 |
| 341 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); | 348 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 recovered_referral_list)); | 535 recovered_referral_list)); |
| 529 EXPECT_EQ(kLatencyNotFound, | 536 EXPECT_EQ(kLatencyNotFound, |
| 530 GetLatencyFromSerialization(motivation_hostname, | 537 GetLatencyFromSerialization(motivation_hostname, |
| 531 img_subresource_hostname, | 538 img_subresource_hostname, |
| 532 recovered_referral_list)); | 539 recovered_referral_list)); |
| 533 | 540 |
| 534 master.Shutdown(); | 541 master.Shutdown(); |
| 535 } | 542 } |
| 536 | 543 |
| 537 } // namespace chrome_browser_net | 544 } // namespace chrome_browser_net |
| OLD | NEW |