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

Side by Side Diff: net/base/host_resolver_impl_unittest.cc

Issue 9369045: [net] HostResolverImpl + DnsTransaction + DnsConfigService = Asynchronous DNS ready for experiments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to master. Created 8 years, 10 months 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 | Annotate | Revision Log
OLDNEW
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
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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 new WaitingHostResolverProc(NULL)); 512 new WaitingHostResolverProc(NULL));
512 513
513 CapturingNetLog net_log(CapturingNetLog::kUnbounded); 514 CapturingNetLog net_log(CapturingNetLog::kUnbounded);
514 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 515 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
515 { 516 {
516 // This resolver will be destroyed while a lookup is running on WorkerPool. 517 // This resolver will be destroyed while a lookup is running on WorkerPool.
517 scoped_ptr<HostResolver> host_resolver( 518 scoped_ptr<HostResolver> host_resolver(
518 new HostResolverImpl(HostCache::CreateDefaultCache(), 519 new HostResolverImpl(HostCache::CreateDefaultCache(),
519 DefaultLimits(), 520 DefaultLimits(),
520 DefaultParams(resolver_proc), 521 DefaultParams(resolver_proc),
522 scoped_ptr<DnsConfigService>(NULL),
521 &net_log)); 523 &net_log));
522 AddressList addrlist; 524 AddressList addrlist;
523 const int kPortnum = 80; 525 const int kPortnum = 80;
524 526
525 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); 527 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum));
526 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL, 528 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL,
527 log.bound()); 529 log.bound());
528 EXPECT_EQ(ERR_IO_PENDING, err); 530 EXPECT_EQ(ERR_IO_PENDING, err);
529 531
530 resolver_proc->Wait(); 532 resolver_proc->Wait();
(...skipping 15 matching lines...) Expand all
546 548
547 int pos = ExpectLogContainsSomewhereAfter(net_log_entries, 0, 549 int pos = ExpectLogContainsSomewhereAfter(net_log_entries, 0,
548 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, 550 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST,
549 NetLog::PHASE_BEGIN); 551 NetLog::PHASE_BEGIN);
550 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, 552 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1,
551 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, 553 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB,
552 NetLog::PHASE_BEGIN); 554 NetLog::PHASE_BEGIN);
553 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, 555 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1,
554 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, 556 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK,
555 NetLog::PHASE_BEGIN); 557 NetLog::PHASE_BEGIN);
556 // Both Request and ProcTask need to be cancelled. (The Job is "aborted".) 558
557 pos = ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, 559 // The Request needs to be cancelled. (The Job is "aborted".)
558 NetLog::TYPE_CANCELLED, 560 // 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, 561 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1,
563 NetLog::TYPE_CANCELLED, 562 NetLog::TYPE_CANCELLED,
564 NetLog::PHASE_NONE); 563 NetLog::PHASE_NONE);
565 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, 564 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1,
565 NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK,
566 NetLog::PHASE_END);
567 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1,
566 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, 568 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST,
567 NetLog::PHASE_END); 569 NetLog::PHASE_END);
568 ExpectLogContainsSomewhereAfter(net_log_entries, pos + 1, 570 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, 571 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB,
573 NetLog::PHASE_END); 572 NetLog::PHASE_END);
574 573
575 EXPECT_FALSE(callback_called_); 574 EXPECT_FALSE(callback_called_);
576 } 575 }
577 576
578 TEST_F(HostResolverImplTest, NumericIPv4Address) { 577 TEST_F(HostResolverImplTest, NumericIPv4Address) {
579 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. 578 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in.
580 579
581 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( 580 scoped_refptr<RuleBasedHostResolverProc> resolver_proc(
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 965
967 TEST_F(HostResolverImplTest, StartWithinCallback) { 966 TEST_F(HostResolverImplTest, StartWithinCallback) {
968 // Use a capturing resolver_proc, since the verifier needs to know what calls 967 // Use a capturing resolver_proc, since the verifier needs to know what calls
969 // reached Resolver(). Also, the capturing resolver_proc is initially 968 // reached Resolver(). Also, the capturing resolver_proc is initially
970 // blocked. 969 // blocked.
971 scoped_refptr<CapturingHostResolverProc> resolver_proc( 970 scoped_refptr<CapturingHostResolverProc> resolver_proc(
972 new CapturingHostResolverProc(NULL)); 971 new CapturingHostResolverProc(NULL));
973 972
974 // Turn off caching for this host resolver. 973 // Turn off caching for this host resolver.
975 scoped_ptr<HostResolver> host_resolver(new HostResolverImpl( 974 scoped_ptr<HostResolver> host_resolver(new HostResolverImpl(
976 NULL, DefaultLimits(), DefaultParams(resolver_proc), NULL)); 975 NULL,
976 DefaultLimits(),
977 DefaultParams(resolver_proc),
978 scoped_ptr<DnsConfigService>(NULL),
979 NULL));
977 980
978 // The class will receive callbacks for when each resolve completes. It 981 // The class will receive callbacks for when each resolve completes. It
979 // checks that the right things happened. 982 // checks that the right things happened.
980 StartWithinCallbackVerifier verifier; 983 StartWithinCallbackVerifier verifier;
981 984
982 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is 985 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is
983 // blocked, these should all pile up until we signal it. 986 // blocked, these should all pile up until we signal it.
984 987
985 ResolveRequest req1(host_resolver.get(), "a", 80, &verifier); 988 ResolveRequest req1(host_resolver.get(), "a", 80, &verifier);
986 ResolveRequest req2(host_resolver.get(), "a", 81, &verifier); 989 ResolveRequest req2(host_resolver.get(), "a", 81, &verifier);
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 // the host. First and second attempt will be forced to sleep until they get 1571 // 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 1572 // word that a resolution has completed. The 3rd resolution attempt will try
1570 // to get done ASAP, and won't sleep.. 1573 // to get done ASAP, and won't sleep..
1571 int kAttemptNumberToResolve = 3; 1574 int kAttemptNumberToResolve = 3;
1572 int kTotalAttempts = 3; 1575 int kTotalAttempts = 3;
1573 1576
1574 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc( 1577 scoped_refptr<LookupAttemptHostResolverProc> resolver_proc(
1575 new LookupAttemptHostResolverProc( 1578 new LookupAttemptHostResolverProc(
1576 NULL, kAttemptNumberToResolve, kTotalAttempts)); 1579 NULL, kAttemptNumberToResolve, kTotalAttempts));
1577 1580
1578 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); 1581 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc.get());
1579 1582
1580 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so 1583 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so
1581 // that unit test runs faster. For example, this test finishes in 1.5 secs 1584 // that unit test runs faster. For example, this test finishes in 1.5 secs
1582 // (500ms * 3). 1585 // (500ms * 3).
1583 params.unresponsive_delay = TimeDelta::FromMilliseconds(500); 1586 params.unresponsive_delay = TimeDelta::FromMilliseconds(500);
1584 1587
1585 scoped_ptr<HostResolverImpl> host_resolver( 1588 scoped_ptr<HostResolverImpl> host_resolver(
1586 new HostResolverImpl(HostCache::CreateDefaultCache(), 1589 new HostResolverImpl(HostCache::CreateDefaultCache(),
1587 DefaultLimits(), 1590 DefaultLimits(),
1588 params, 1591 params,
1592 scoped_ptr<DnsConfigService>(NULL),
1589 NULL)); 1593 NULL));
1590 1594
1591 // Resolve "host1". 1595 // Resolve "host1".
1592 HostResolver::RequestInfo info(HostPortPair("host1", 70)); 1596 HostResolver::RequestInfo info(HostPortPair("host1", 70));
1593 TestCompletionCallback callback; 1597 TestCompletionCallback callback;
1594 AddressList addrlist; 1598 AddressList addrlist;
1595 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, 1599 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL,
1596 BoundNetLog()); 1600 BoundNetLog());
1597 EXPECT_EQ(ERR_IO_PENDING, rv); 1601 EXPECT_EQ(ERR_IO_PENDING, rv);
1598 1602
1599 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. 1603 // Resolve returns -4 to indicate that 3rd attempt has resolved the host.
1600 EXPECT_EQ(-4, callback.WaitForResult()); 1604 EXPECT_EQ(-4, callback.WaitForResult());
1601 1605
1602 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); 1606 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000));
1603 MessageLoop::current()->RunAllPending(); 1607 MessageLoop::current()->RunAllPending();
1604 1608
1605 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); 1609 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts);
1606 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); 1610 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve);
1607 } 1611 }
1608 1612
1609 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. 1613 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags.
1610 1614
1611 } // namespace net 1615 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698