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

Side by Side Diff: net/socket/client_socket_pool_base_unittest.cc

Issue 4118004: Update NetLog to be thread safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final sync with trunk Created 10 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_service_unittest.cc ('k') | net/socket/socks5_client_socket_unittest.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/platform_thread.h" 10 #include "base/platform_thread.h"
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 "a", 613 "a",
614 request, 614 request,
615 base::TimeDelta::FromMicroseconds(1), 615 base::TimeDelta::FromMicroseconds(1),
616 &delegate, 616 &delegate,
617 &client_socket_factory_, 617 &client_socket_factory_,
618 &log); 618 &log);
619 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); 619 ASSERT_EQ(ERR_IO_PENDING, job->Connect());
620 PlatformThread::Sleep(1); 620 PlatformThread::Sleep(1);
621 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); 621 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult());
622 622
623 EXPECT_EQ(6u, log.entries().size()); 623 net::CapturingNetLog::EntryList entries;
624 log.GetEntries(&entries);
625
626 EXPECT_EQ(6u, entries.size());
624 EXPECT_TRUE(LogContainsBeginEvent( 627 EXPECT_TRUE(LogContainsBeginEvent(
625 log.entries(), 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); 628 entries, 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB));
626 EXPECT_TRUE(LogContainsBeginEvent( 629 EXPECT_TRUE(LogContainsBeginEvent(
627 log.entries(), 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); 630 entries, 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT));
628 EXPECT_TRUE(LogContainsEvent( 631 EXPECT_TRUE(LogContainsEvent(
629 log.entries(), 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET, 632 entries, 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET,
630 NetLog::PHASE_NONE)); 633 NetLog::PHASE_NONE));
631 EXPECT_TRUE(LogContainsEvent( 634 EXPECT_TRUE(LogContainsEvent(
632 log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, 635 entries, 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT,
633 NetLog::PHASE_NONE)); 636 NetLog::PHASE_NONE));
634 EXPECT_TRUE(LogContainsEndEvent( 637 EXPECT_TRUE(LogContainsEndEvent(
635 log.entries(), 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); 638 entries, 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT));
636 EXPECT_TRUE(LogContainsEndEvent( 639 EXPECT_TRUE(LogContainsEndEvent(
637 log.entries(), 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); 640 entries, 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB));
638 } 641 }
639 642
640 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { 643 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) {
641 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 644 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
642 645
643 TestCompletionCallback callback; 646 TestCompletionCallback callback;
644 ClientSocketHandle handle; 647 ClientSocketHandle handle;
645 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 648 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
646 649
647 EXPECT_EQ(OK, 650 EXPECT_EQ(OK,
648 handle.Init("a", 651 handle.Init("a",
649 params_, 652 params_,
650 kDefaultPriority, 653 kDefaultPriority,
651 &callback, 654 &callback,
652 pool_.get(), 655 pool_.get(),
653 log.bound())); 656 log.bound()));
654 EXPECT_TRUE(handle.is_initialized()); 657 EXPECT_TRUE(handle.is_initialized());
655 EXPECT_TRUE(handle.socket()); 658 EXPECT_TRUE(handle.socket());
656 handle.Reset(); 659 handle.Reset();
657 660
658 EXPECT_EQ(4u, log.entries().size()); 661 net::CapturingNetLog::EntryList entries;
662 log.GetEntries(&entries);
663
664 EXPECT_EQ(4u, entries.size());
659 EXPECT_TRUE(LogContainsBeginEvent( 665 EXPECT_TRUE(LogContainsBeginEvent(
660 log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); 666 entries, 0, NetLog::TYPE_SOCKET_POOL));
661 EXPECT_TRUE(LogContainsEvent( 667 EXPECT_TRUE(LogContainsEvent(
662 log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 668 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
663 NetLog::PHASE_NONE)); 669 NetLog::PHASE_NONE));
664 EXPECT_TRUE(LogContainsEvent( 670 EXPECT_TRUE(LogContainsEvent(
665 log.entries(), 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 671 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
666 NetLog::PHASE_NONE)); 672 NetLog::PHASE_NONE));
667 EXPECT_TRUE(LogContainsEndEvent( 673 EXPECT_TRUE(LogContainsEndEvent(
668 log.entries(), 3, NetLog::TYPE_SOCKET_POOL)); 674 entries, 3, NetLog::TYPE_SOCKET_POOL));
669 } 675 }
670 676
671 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { 677 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) {
672 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 678 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
673 679
674 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); 680 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob);
675 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 681 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
676 682
677 ClientSocketHandle handle; 683 ClientSocketHandle handle;
678 TestCompletionCallback callback; 684 TestCompletionCallback callback;
679 // Set the additional error state members to ensure that they get cleared. 685 // Set the additional error state members to ensure that they get cleared.
680 handle.set_is_ssl_error(true); 686 handle.set_is_ssl_error(true);
681 HttpResponseInfo info; 687 HttpResponseInfo info;
682 info.headers = new HttpResponseHeaders(""); 688 info.headers = new HttpResponseHeaders("");
683 handle.set_ssl_error_response_info(info); 689 handle.set_ssl_error_response_info(info);
684 EXPECT_EQ(ERR_CONNECTION_FAILED, 690 EXPECT_EQ(ERR_CONNECTION_FAILED,
685 handle.Init("a", 691 handle.Init("a",
686 params_, 692 params_,
687 kDefaultPriority, 693 kDefaultPriority,
688 &callback, 694 &callback,
689 pool_.get(), 695 pool_.get(),
690 log.bound())); 696 log.bound()));
691 EXPECT_FALSE(handle.socket()); 697 EXPECT_FALSE(handle.socket());
692 EXPECT_FALSE(handle.is_ssl_error()); 698 EXPECT_FALSE(handle.is_ssl_error());
693 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); 699 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
694 700
695 EXPECT_EQ(3u, log.entries().size()); 701 net::CapturingNetLog::EntryList entries;
702 log.GetEntries(&entries);
703
704 EXPECT_EQ(3u, entries.size());
696 EXPECT_TRUE(LogContainsBeginEvent( 705 EXPECT_TRUE(LogContainsBeginEvent(
697 log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); 706 entries, 0, NetLog::TYPE_SOCKET_POOL));
698 EXPECT_TRUE(LogContainsEvent( 707 EXPECT_TRUE(LogContainsEvent(
699 log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 708 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
700 NetLog::PHASE_NONE)); 709 NetLog::PHASE_NONE));
701 EXPECT_TRUE(LogContainsEndEvent( 710 EXPECT_TRUE(LogContainsEndEvent(
702 log.entries(), 2, NetLog::TYPE_SOCKET_POOL)); 711 entries, 2, NetLog::TYPE_SOCKET_POOL));
703 } 712 }
704 713
705 TEST_F(ClientSocketPoolBaseTest, TotalLimit) { 714 TEST_F(ClientSocketPoolBaseTest, TotalLimit) {
706 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 715 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
707 716
708 // TODO(eroman): Check that the NetLog contains this event. 717 // TODO(eroman): Check that the NetLog contains this event.
709 718
710 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); 719 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
711 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); 720 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority));
712 EXPECT_EQ(OK, StartRequest("c", kDefaultPriority)); 721 EXPECT_EQ(OK, StartRequest("c", kDefaultPriority));
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 &callback, 1505 &callback,
1497 pool_.get(), 1506 pool_.get(),
1498 log.bound()); 1507 log.bound());
1499 EXPECT_EQ(ERR_IO_PENDING, rv); 1508 EXPECT_EQ(ERR_IO_PENDING, rv);
1500 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); 1509 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
1501 EXPECT_EQ(OK, callback.WaitForResult()); 1510 EXPECT_EQ(OK, callback.WaitForResult());
1502 EXPECT_TRUE(handle.is_initialized()); 1511 EXPECT_TRUE(handle.is_initialized());
1503 EXPECT_TRUE(handle.socket()); 1512 EXPECT_TRUE(handle.socket());
1504 handle.Reset(); 1513 handle.Reset();
1505 1514
1506 EXPECT_EQ(4u, log.entries().size()); 1515 net::CapturingNetLog::EntryList entries;
1516 log.GetEntries(&entries);
1517
1518 EXPECT_EQ(4u, entries.size());
1507 EXPECT_TRUE(LogContainsBeginEvent( 1519 EXPECT_TRUE(LogContainsBeginEvent(
1508 log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); 1520 entries, 0, NetLog::TYPE_SOCKET_POOL));
1509 EXPECT_TRUE(LogContainsEvent( 1521 EXPECT_TRUE(LogContainsEvent(
1510 log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 1522 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
1511 NetLog::PHASE_NONE)); 1523 NetLog::PHASE_NONE));
1512 EXPECT_TRUE(LogContainsEvent( 1524 EXPECT_TRUE(LogContainsEvent(
1513 log.entries(), 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 1525 entries, 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
1514 NetLog::PHASE_NONE)); 1526 NetLog::PHASE_NONE));
1515 EXPECT_TRUE(LogContainsEndEvent( 1527 EXPECT_TRUE(LogContainsEndEvent(
1516 log.entries(), 3, NetLog::TYPE_SOCKET_POOL)); 1528 entries, 3, NetLog::TYPE_SOCKET_POOL));
1517 } 1529 }
1518 1530
1519 TEST_F(ClientSocketPoolBaseTest, 1531 TEST_F(ClientSocketPoolBaseTest,
1520 InitConnectionAsynchronousFailure) { 1532 InitConnectionAsynchronousFailure) {
1521 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1533 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1522 1534
1523 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); 1535 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
1524 ClientSocketHandle handle; 1536 ClientSocketHandle handle;
1525 TestCompletionCallback callback; 1537 TestCompletionCallback callback;
1526 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1538 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1527 // Set the additional error state members to ensure that they get cleared. 1539 // Set the additional error state members to ensure that they get cleared.
1528 handle.set_is_ssl_error(true); 1540 handle.set_is_ssl_error(true);
1529 HttpResponseInfo info; 1541 HttpResponseInfo info;
1530 info.headers = new HttpResponseHeaders(""); 1542 info.headers = new HttpResponseHeaders("");
1531 handle.set_ssl_error_response_info(info); 1543 handle.set_ssl_error_response_info(info);
1532 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", 1544 EXPECT_EQ(ERR_IO_PENDING, handle.Init("a",
1533 params_, 1545 params_,
1534 kDefaultPriority, 1546 kDefaultPriority,
1535 &callback, 1547 &callback,
1536 pool_.get(), 1548 pool_.get(),
1537 log.bound())); 1549 log.bound()));
1538 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); 1550 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle));
1539 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); 1551 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult());
1540 EXPECT_FALSE(handle.is_ssl_error()); 1552 EXPECT_FALSE(handle.is_ssl_error());
1541 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL); 1553 EXPECT_TRUE(handle.ssl_error_response_info().headers.get() == NULL);
1542 1554
1543 EXPECT_EQ(3u, log.entries().size()); 1555 net::CapturingNetLog::EntryList entries;
1556 log.GetEntries(&entries);
1557
1558 EXPECT_EQ(3u, entries.size());
1544 EXPECT_TRUE(LogContainsBeginEvent( 1559 EXPECT_TRUE(LogContainsBeginEvent(
1545 log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); 1560 entries, 0, NetLog::TYPE_SOCKET_POOL));
1546 EXPECT_TRUE(LogContainsEvent( 1561 EXPECT_TRUE(LogContainsEvent(
1547 log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 1562 entries, 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
1548 NetLog::PHASE_NONE)); 1563 NetLog::PHASE_NONE));
1549 EXPECT_TRUE(LogContainsEndEvent( 1564 EXPECT_TRUE(LogContainsEndEvent(
1550 log.entries(), 2, NetLog::TYPE_SOCKET_POOL)); 1565 entries, 2, NetLog::TYPE_SOCKET_POOL));
1551 } 1566 }
1552 1567
1553 TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { 1568 TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) {
1554 // TODO(eroman): Add back the log expectations! Removed them because the 1569 // TODO(eroman): Add back the log expectations! Removed them because the
1555 // ordering is difficult, and some may fire during destructor. 1570 // ordering is difficult, and some may fire during destructor.
1556 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1571 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
1557 1572
1558 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 1573 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
1559 ClientSocketHandle handle; 1574 ClientSocketHandle handle;
1560 TestCompletionCallback callback; 1575 TestCompletionCallback callback;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 pool_->CleanupTimedOutIdleSockets(); 1900 pool_->CleanupTimedOutIdleSockets();
1886 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1901 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1887 rv = handle.Init("a", 1902 rv = handle.Init("a",
1888 params_, 1903 params_,
1889 LOWEST, 1904 LOWEST,
1890 &callback, 1905 &callback,
1891 pool_.get(), 1906 pool_.get(),
1892 log.bound()); 1907 log.bound());
1893 EXPECT_EQ(OK, rv); 1908 EXPECT_EQ(OK, rv);
1894 EXPECT_TRUE(handle.is_reused()); 1909 EXPECT_TRUE(handle.is_reused());
1910
1911 net::CapturingNetLog::EntryList entries;
1912 log.GetEntries(&entries);
1895 EXPECT_TRUE(LogContainsEntryWithType( 1913 EXPECT_TRUE(LogContainsEntryWithType(
1896 log.entries(), 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET)); 1914 entries, 1, NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET));
1897 } 1915 }
1898 1916
1899 // Make sure that we process all pending requests even when we're stalling 1917 // Make sure that we process all pending requests even when we're stalling
1900 // because of multiple releasing disconnected sockets. 1918 // because of multiple releasing disconnected sockets.
1901 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { 1919 TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) {
1902 CreatePoolWithIdleTimeouts( 1920 CreatePoolWithIdleTimeouts(
1903 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup, 1921 kDefaultMaxSockets, kDefaultMaxSocketsPerGroup,
1904 base::TimeDelta(), // Time out unused sockets immediately. 1922 base::TimeDelta(), // Time out unused sockets immediately.
1905 base::TimeDelta::FromDays(1)); // Don't time out used sockets. 1923 base::TimeDelta::FromDays(1)); // Don't time out used sockets.
1906 1924
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2993 ASSERT_EQ(OK, callback1.WaitForResult()); 3011 ASSERT_EQ(OK, callback1.WaitForResult());
2994 3012
2995 handle1.Reset(); 3013 handle1.Reset();
2996 3014
2997 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a")); 3015 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a"));
2998 } 3016 }
2999 3017
3000 } // namespace 3018 } // namespace
3001 3019
3002 } // namespace net 3020 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service_unittest.cc ('k') | net/socket/socks5_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698