diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 22:49:10 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 22:49:10 +0000 |
commit | 562dbaec88e244316208d0df71262bc2461725dd (patch) | |
tree | 70c39561713b1c9ee529c49703847a90b6aa88a3 /chrome/browser | |
parent | 4db3a01e07bc008b8a567c0735dbd813a49a617b (diff) | |
download | chromium_src-562dbaec88e244316208d0df71262bc2461725dd.zip chromium_src-562dbaec88e244316208d0df71262bc2461725dd.tar.gz chromium_src-562dbaec88e244316208d0df71262bc2461725dd.tar.bz2 |
Remove the unittest "DnsMasterTest.OsCachesLookupsTest".
This test was checking that the system host resolver maintains an internal cache, by doing actual DNS resolves (which introduces a network dependency in the unit tests). This could be flaky on linux, which doesn't cache resolves.
As of r18236 however, chromium maintains its own host cache. So the DNS prefetcher does not need to rely on the OS caching DNS resolves in order to be a win.
BUG=http://crbug.com/18766
Review URL: http://codereview.chromium.org/164350
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23239 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/net/dns_master_unittest.cc | 77 |
1 files changed, 5 insertions, 72 deletions
diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc index 18e5d05..fc8b796d 100644 --- a/chrome/browser/net/dns_master_unittest.cc +++ b/chrome/browser/net/dns_master_unittest.cc @@ -59,7 +59,7 @@ class WaitForResolutionHelper { class DnsMasterTest : public testing::Test { public: DnsMasterTest() - : host_resolver_(new net::MockHostResolver()), + : host_resolver_(new net::MockCachingHostResolver()), default_max_queueing_delay_(TimeDelta::FromMilliseconds( DnsPrefetcherInit::kMaxQueueingDelayMs)) { } @@ -69,6 +69,9 @@ class DnsMasterTest : public testing::Test { #if defined(OS_WIN) net::EnsureWinsockInit(); #endif + // Since we are using a caching HostResolver, the following latencies will + // only be incurred by the first request, after which the result will be + // cached internally by |host_resolver_|. net::RuleBasedHostResolverProc* rules = host_resolver_->rules(); rules->AddRuleWithLatency("www.google.com", "127.0.0.1", 50); rules->AddRuleWithLatency("gmail.google.com.com", "127.0.0.1", 70); @@ -91,7 +94,7 @@ class DnsMasterTest : public testing::Test { MessageLoop loop; protected: - scoped_refptr<net::MockHostResolver> host_resolver_; + scoped_refptr<net::MockCachingHostResolver> host_resolver_; // Shorthand to access TimeDelta of DnsPrefetcherInit::kMaxQueueingDelayMs. // (It would be a static constant... except style rules preclude that :-/ ). @@ -99,76 +102,6 @@ class DnsMasterTest : public testing::Test { }; //------------------------------------------------------------------------------ -// Provide a function to create unique (nonexistant) domains at *every* call. -//------------------------------------------------------------------------------ -static std::string GetNonexistantDomain() { - static std::string postfix = ".google.com"; - static std::string prefix = "www."; - static std::string mid = "datecount"; - - static int counter = 0; // Make sure its unique. - time_t number = time(NULL); - std::ostringstream result; - result << prefix << number << mid << ++counter << postfix; - return result.str(); -} - -//------------------------------------------------------------------------------ -// Use a blocking function to contrast results we get via async services. -//------------------------------------------------------------------------------ -TimeDelta BlockingDnsLookup(net::HostResolver* resolver, - const std::string& hostname) { - Time start = Time::Now(); - - net::AddressList addresses; - net::HostResolver::RequestInfo info(hostname, 80); - resolver->Resolve(NULL, info, &addresses, NULL, NULL); - - return Time::Now() - start; -} - -//------------------------------------------------------------------------------ - -// First test to be sure the OS is caching lookups, which is the whole premise -// of DNS prefetching. -TEST_F(DnsMasterTest, OsCachesLookupsTest) { - host_resolver_->rules()->AllowDirectLookup("*.google.com"); - - const Time start = Time::Now(); - int all_lookups = 0; - int lookups_with_improvement = 0; - // This test can be really flaky on Linux. It should run in much shorter time, - // but sometimes it won't and we don't like bogus failures. - while (Time::Now() - start < TimeDelta::FromMinutes(1)) { - std::string badname; - badname = GetNonexistantDomain(); - - TimeDelta duration = BlockingDnsLookup(host_resolver_, badname); - - // Produce more than one result and remove the largest one - // to reduce flakiness. - std::vector<TimeDelta> cached_results; - for (int j = 0; j < 3; j++) - cached_results.push_back(BlockingDnsLookup(host_resolver_, badname)); - std::sort(cached_results.begin(), cached_results.end()); - cached_results.pop_back(); - - TimeDelta cached_sum = TimeDelta::FromSeconds(0); - for (std::vector<TimeDelta>::const_iterator j = cached_results.begin(); - j != cached_results.end(); ++j) - cached_sum += *j; - TimeDelta cached_duration = cached_sum / cached_results.size(); - - all_lookups++; - if (cached_duration < duration) - lookups_with_improvement++; - if (all_lookups >= 10) - if (lookups_with_improvement * 100 > all_lookups * 75) - // Okay, we see the improvement for more than 75% of all lookups. - return; - } - FAIL() << "No substantial improvement in lookup time."; -} TEST_F(DnsMasterTest, StartupShutdownTest) { scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |