Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/browser/net/dns_master_unittest.cc

Issue 14919: Platform cleanup in chrome/browser/net. (Closed)
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/net/dns_master.cc ('k') | chrome/browser/net/dns_slave.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Multi-threaded tests of DnsMaster and DnsPrefetch slave functionality. 5 // Multi-threaded tests of DnsMaster and DnsPrefetch slave functionality.
6 6
7 #include <time.h> 7 #include <time.h>
8 #include <ws2tcpip.h> 8 #include <ws2tcpip.h>
9 #include <Wspiapi.h> // Needed for win2k compatibility 9 #include <Wspiapi.h> // Needed for win2k compatibility
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <map> 12 #include <map>
13 #include <sstream> 13 #include <sstream>
14 #include <string> 14 #include <string>
15 15
16 #include "base/platform_thread.h"
16 #include "base/spin_wait.h" 17 #include "base/spin_wait.h"
17 #include "chrome/browser/net/dns_global.h" 18 #include "chrome/browser/net/dns_global.h"
18 #include "chrome/browser/net/dns_host_info.h" 19 #include "chrome/browser/net/dns_host_info.h"
19 #include "chrome/browser/net/dns_slave.h" 20 #include "chrome/browser/net/dns_slave.h"
20 #include "net/base/winsock_init.h" 21 #include "net/base/winsock_init.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 24
24 using base::Time; 25 using base::Time;
25 using base::TimeDelta; 26 using base::TimeDelta;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 if (latency.end() != latency.find(hostname)) { 83 if (latency.end() != latency.find(hostname)) {
83 duration = latency[hostname]; 84 duration = latency[hostname];
84 } else { 85 } else {
85 duration = 500; 86 duration = 500;
86 } 87 }
87 // Change latency to simulate cache warming (next latency will be short). 88 // Change latency to simulate cache warming (next latency will be short).
88 latency[hostname] = 1; 89 latency[hostname] = 1;
89 } // Release lock. 90 } // Release lock.
90 91
91 Sleep(duration); 92 PlatformThread::Sleep(duration);
92 93
93 return was_found ? 0 : WSAHOST_NOT_FOUND; 94 return was_found ? 0 : WSAHOST_NOT_FOUND;
94 } 95 }
95 96
96 static void SetupNetworkInfrastructure() { 97 static void SetupNetworkInfrastructure() {
97 bool kUseFakeNetwork = true; 98 bool kUseFakeNetwork = true;
98 if (kUseFakeNetwork) 99 if (kUseFakeNetwork)
99 chrome_browser_net::SetAddrinfoCallbacks(fake_get_addr_info, 100 chrome_browser_net::SetAddrinfoCallbacks(fake_get_addr_info,
100 fake_free_addr_info); 101 fake_free_addr_info);
101 } 102 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(0 <= 278 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(0 <=
278 testing_master.GetResolutionDuration(bad2).InMilliseconds()); 279 testing_master.GetResolutionDuration(bad2).InMilliseconds());
279 280
280 // Verify both fictitious names are resolved by now. 281 // Verify both fictitious names are resolved by now.
281 // Typical random name takes about 20-30 ms 282 // Typical random name takes about 20-30 ms
282 EXPECT_LT(0, testing_master.GetResolutionDuration(bad1).InMilliseconds()); 283 EXPECT_LT(0, testing_master.GetResolutionDuration(bad1).InMilliseconds());
283 EXPECT_LT(0, testing_master.GetResolutionDuration(bad2).InMilliseconds()); 284 EXPECT_LT(0, testing_master.GetResolutionDuration(bad2).InMilliseconds());
284 EXPECT_FALSE(testing_master.WasFound(bad1)); 285 EXPECT_FALSE(testing_master.WasFound(bad1));
285 EXPECT_FALSE(testing_master.WasFound(bad2)); 286 EXPECT_FALSE(testing_master.WasFound(bad2));
286 287
287 EXPECT_EQ(1, testing_master.running_slave_count()); 288 EXPECT_EQ(1U, testing_master.running_slave_count());
288 289
289 // With just one thread (doing nothing now), ensure a clean shutdown. 290 // With just one thread (doing nothing now), ensure a clean shutdown.
290 EXPECT_TRUE(testing_master.ShutdownSlaves()); 291 EXPECT_TRUE(testing_master.ShutdownSlaves());
291 } 292 }
292 293
293 TEST(DnsMasterTest, DISABLED_MultiThreadedLookupTest) { 294 TEST(DnsMasterTest, DISABLED_MultiThreadedLookupTest) {
294 SetupNetworkInfrastructure(); 295 SetupNetworkInfrastructure();
295 net::EnsureWinsockInit(); 296 net::EnsureWinsockInit();
296 DnsMaster testing_master(TimeDelta::FromSeconds(30)); 297 DnsMaster testing_master(TimeDelta::FromSeconds(30));
297 DnsPrefetcherInit dns_init(NULL); 298 DnsPrefetcherInit dns_init(NULL);
(...skipping 27 matching lines...) Expand all
325 326
326 Sleep(10); // Allow time for async DNS to get answers. 327 Sleep(10); // Allow time for async DNS to get answers.
327 328
328 EXPECT_TRUE(testing_master.WasFound(goog)); 329 EXPECT_TRUE(testing_master.WasFound(goog));
329 EXPECT_TRUE(testing_master.WasFound(goog3)); 330 EXPECT_TRUE(testing_master.WasFound(goog3));
330 EXPECT_TRUE(testing_master.WasFound(goog2)); 331 EXPECT_TRUE(testing_master.WasFound(goog2));
331 EXPECT_TRUE(testing_master.WasFound(goog4)); 332 EXPECT_TRUE(testing_master.WasFound(goog4));
332 EXPECT_FALSE(testing_master.WasFound(bad1)); 333 EXPECT_FALSE(testing_master.WasFound(bad1));
333 EXPECT_FALSE(testing_master.WasFound(bad2)); 334 EXPECT_FALSE(testing_master.WasFound(bad2));
334 335
335 EXPECT_EQ(8, testing_master.running_slave_count()); 336 EXPECT_EQ(8U, testing_master.running_slave_count());
336 337
337 EXPECT_TRUE(testing_master.ShutdownSlaves()); 338 EXPECT_TRUE(testing_master.ShutdownSlaves());
338 } 339 }
339 340
340 TEST(DnsMasterTest, DISABLED_MultiThreadedSpeedupTest) { 341 TEST(DnsMasterTest, DISABLED_MultiThreadedSpeedupTest) {
341 SetupNetworkInfrastructure(); 342 SetupNetworkInfrastructure();
342 net::EnsureWinsockInit(); 343 net::EnsureWinsockInit();
343 DnsMaster testing_master(TimeDelta::FromSeconds(30)); 344 DnsMaster testing_master(TimeDelta::FromSeconds(30));
344 DnsPrefetcherInit dns_init(NULL); 345 DnsPrefetcherInit dns_init(NULL);
345 346
(...skipping 25 matching lines...) Expand all
371 372
372 EXPECT_TRUE(testing_master.WasFound(goog)); 373 EXPECT_TRUE(testing_master.WasFound(goog));
373 EXPECT_FALSE(testing_master.WasFound(bad1)); 374 EXPECT_FALSE(testing_master.WasFound(bad1));
374 EXPECT_FALSE(testing_master.WasFound(bad2)); 375 EXPECT_FALSE(testing_master.WasFound(bad2));
375 // ...and due to delay in geting resolution of bad names, the single slave 376 // ...and due to delay in geting resolution of bad names, the single slave
376 // thread won't have time to finish the list. 377 // thread won't have time to finish the list.
377 EXPECT_FALSE(testing_master.WasFound(goog3)); 378 EXPECT_FALSE(testing_master.WasFound(goog3));
378 EXPECT_FALSE(testing_master.WasFound(goog2)); 379 EXPECT_FALSE(testing_master.WasFound(goog2));
379 EXPECT_FALSE(testing_master.WasFound(goog4)); 380 EXPECT_FALSE(testing_master.WasFound(goog4));
380 381
381 EXPECT_EQ(1, testing_master.running_slave_count()); 382 EXPECT_EQ(1U, testing_master.running_slave_count());
382 383
383 // Get all 8 threads running by calling many times before queue is handled. 384 // Get all 8 threads running by calling many times before queue is handled.
384 names.clear(); 385 names.clear();
385 for (int i = 0; i < 10; i++) 386 for (int i = 0; i < 10; i++)
386 testing_master.Resolve(GetNonexistantDomain(), 387 testing_master.Resolve(GetNonexistantDomain(),
387 DnsHostInfo::PAGE_SCAN_MOTIVATED); 388 DnsHostInfo::PAGE_SCAN_MOTIVATED);
388 389
389 // Wait long enough for all the goog's to be resolved. 390 // Wait long enough for all the goog's to be resolved.
390 // They should all take about the same time, and run in parallel. 391 // They should all take about the same time, and run in parallel.
391 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(0 <= 392 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(0 <=
(...skipping 23 matching lines...) Expand all
415 testing_master.GetResolutionDuration(bad2).InMilliseconds()); 416 testing_master.GetResolutionDuration(bad2).InMilliseconds());
416 417
417 418
418 // Well known names should resolve faster than bad names. 419 // Well known names should resolve faster than bad names.
419 EXPECT_GE(testing_master.GetResolutionDuration(bad1).InMilliseconds(), 420 EXPECT_GE(testing_master.GetResolutionDuration(bad1).InMilliseconds(),
420 testing_master.GetResolutionDuration(goog).InMilliseconds()); 421 testing_master.GetResolutionDuration(goog).InMilliseconds());
421 422
422 EXPECT_GE(testing_master.GetResolutionDuration(bad2).InMilliseconds(), 423 EXPECT_GE(testing_master.GetResolutionDuration(bad2).InMilliseconds(),
423 testing_master.GetResolutionDuration(goog4).InMilliseconds()); 424 testing_master.GetResolutionDuration(goog4).InMilliseconds());
424 425
425 EXPECT_EQ(8, testing_master.running_slave_count()); 426 EXPECT_EQ(8U, testing_master.running_slave_count());
426 427
427 EXPECT_TRUE(testing_master.ShutdownSlaves()); 428 EXPECT_TRUE(testing_master.ShutdownSlaves());
428 } 429 }
429 430
430 } // namespace 431 } // namespace
431 432
OLDNEW
« no previous file with comments | « chrome/browser/net/dns_master.cc ('k') | chrome/browser/net/dns_slave.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698