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

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

Issue 18796003: When an idle socket is added back to a socket pool, check for stalled jobs in lower pools (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update comments Created 7 years, 4 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
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/socks_client_socket_pool.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) 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/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include <vector> 7 #include <vector>
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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 public: 470 public:
471 typedef TestSocketParams SocketParams; 471 typedef TestSocketParams SocketParams;
472 472
473 TestClientSocketPool( 473 TestClientSocketPool(
474 int max_sockets, 474 int max_sockets,
475 int max_sockets_per_group, 475 int max_sockets_per_group,
476 ClientSocketPoolHistograms* histograms, 476 ClientSocketPoolHistograms* histograms,
477 base::TimeDelta unused_idle_socket_timeout, 477 base::TimeDelta unused_idle_socket_timeout,
478 base::TimeDelta used_idle_socket_timeout, 478 base::TimeDelta used_idle_socket_timeout,
479 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory) 479 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory)
480 : base_(max_sockets, max_sockets_per_group, histograms, 480 : base_(NULL, max_sockets, max_sockets_per_group, histograms,
481 unused_idle_socket_timeout, used_idle_socket_timeout, 481 unused_idle_socket_timeout, used_idle_socket_timeout,
482 connect_job_factory) {} 482 connect_job_factory) {}
483 483
484 virtual ~TestClientSocketPool() {} 484 virtual ~TestClientSocketPool() {}
485 485
486 virtual int RequestSocket( 486 virtual int RequestSocket(
487 const std::string& group_name, 487 const std::string& group_name,
488 const void* params, 488 const void* params,
489 net::RequestPriority priority, 489 net::RequestPriority priority,
490 ClientSocketHandle* handle, 490 ClientSocketHandle* handle,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 const std::string& group_name) const OVERRIDE { 539 const std::string& group_name) const OVERRIDE {
540 return base_.IdleSocketCountInGroup(group_name); 540 return base_.IdleSocketCountInGroup(group_name);
541 } 541 }
542 542
543 virtual LoadState GetLoadState( 543 virtual LoadState GetLoadState(
544 const std::string& group_name, 544 const std::string& group_name,
545 const ClientSocketHandle* handle) const OVERRIDE { 545 const ClientSocketHandle* handle) const OVERRIDE {
546 return base_.GetLoadState(group_name, handle); 546 return base_.GetLoadState(group_name, handle);
547 } 547 }
548 548
549 virtual void AddLayeredPool(LayeredPool* pool) OVERRIDE { 549 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE {
550 base_.AddLayeredPool(pool); 550 base_.AddHigherLayeredPool(higher_pool);
551 } 551 }
552 552
553 virtual void RemoveLayeredPool(LayeredPool* pool) OVERRIDE { 553 virtual void RemoveHigherLayeredPool(
554 base_.RemoveLayeredPool(pool); 554 HigherLayeredPool* higher_pool) OVERRIDE {
555 base_.RemoveHigherLayeredPool(higher_pool);
555 } 556 }
556 557
557 virtual base::DictionaryValue* GetInfoAsValue( 558 virtual base::DictionaryValue* GetInfoAsValue(
558 const std::string& name, 559 const std::string& name,
559 const std::string& type, 560 const std::string& type,
560 bool include_nested_pools) const OVERRIDE { 561 bool include_nested_pools) const OVERRIDE {
561 return base_.GetInfoAsValue(name, type); 562 return base_.GetInfoAsValue(name, type);
562 } 563 }
563 564
564 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE { 565 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE {
(...skipping 19 matching lines...) Expand all
584 } 585 }
585 586
586 bool HasGroup(const std::string& group_name) const { 587 bool HasGroup(const std::string& group_name) const {
587 return base_.HasGroup(group_name); 588 return base_.HasGroup(group_name);
588 } 589 }
589 590
590 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } 591 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); }
591 592
592 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); } 593 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); }
593 594
594 bool CloseOneIdleConnectionInLayeredPool() { 595 bool CloseOneIdleConnectionInHigherLayeredPool() {
595 return base_.CloseOneIdleConnectionInLayeredPool(); 596 return base_.CloseOneIdleConnectionInHigherLayeredPool();
596 } 597 }
597 598
598 private: 599 private:
599 TestClientSocketPoolBase base_; 600 TestClientSocketPoolBase base_;
600 601
601 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); 602 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool);
602 }; 603 };
603 604
604 } // namespace 605 } // namespace
605 606
(...skipping 3105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3711 ASSERT_EQ(OK, callback.WaitForResult()); 3712 ASSERT_EQ(OK, callback.WaitForResult());
3712 3713
3713 // The hung connect job should still be there, but everything else should be 3714 // The hung connect job should still be there, but everything else should be
3714 // complete. 3715 // complete.
3715 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3716 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3716 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); 3717 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a"));
3717 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3718 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3718 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 3719 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
3719 } 3720 }
3720 3721
3721 class MockLayeredPool : public LayeredPool { 3722 class MockLayeredPool : public HigherLayeredPool {
3722 public: 3723 public:
3723 MockLayeredPool(TestClientSocketPool* pool, 3724 MockLayeredPool(TestClientSocketPool* pool,
3724 const std::string& group_name) 3725 const std::string& group_name)
3725 : pool_(pool), 3726 : pool_(pool),
3726 params_(new TestSocketParams), 3727 params_(new TestSocketParams),
3727 group_name_(group_name), 3728 group_name_(group_name),
3728 can_release_connection_(true) { 3729 can_release_connection_(true) {
3729 pool_->AddLayeredPool(this); 3730 pool_->AddHigherLayeredPool(this);
3730 } 3731 }
3731 3732
3732 ~MockLayeredPool() { 3733 ~MockLayeredPool() {
3733 pool_->RemoveLayeredPool(this); 3734 pool_->RemoveHigherLayeredPool(this);
3734 } 3735 }
3735 3736
3736 int RequestSocket(TestClientSocketPool* pool) { 3737 int RequestSocket(TestClientSocketPool* pool) {
3737 return handle_.Init(group_name_, params_, kDefaultPriority, 3738 return handle_.Init(group_name_, params_, kDefaultPriority,
3738 callback_.callback(), pool, BoundNetLog()); 3739 callback_.callback(), pool, BoundNetLog());
3739 } 3740 }
3740 3741
3741 int RequestSocketWithoutLimits(TestClientSocketPool* pool) { 3742 int RequestSocketWithoutLimits(TestClientSocketPool* pool) {
3742 params_->set_ignore_limits(true); 3743 params_->set_ignore_limits(true);
3743 return handle_.Init(group_name_, params_, kDefaultPriority, 3744 return handle_.Init(group_name_, params_, kDefaultPriority,
(...skipping 25 matching lines...) Expand all
3769 }; 3770 };
3770 3771
3771 TEST_F(ClientSocketPoolBaseTest, FailToCloseIdleSocketsNotHeldByLayeredPool) { 3772 TEST_F(ClientSocketPoolBaseTest, FailToCloseIdleSocketsNotHeldByLayeredPool) {
3772 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 3773 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3773 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 3774 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3774 3775
3775 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); 3776 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3776 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); 3777 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3777 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) 3778 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3778 .WillOnce(Return(false)); 3779 .WillOnce(Return(false));
3779 EXPECT_FALSE(pool_->CloseOneIdleConnectionInLayeredPool()); 3780 EXPECT_FALSE(pool_->CloseOneIdleConnectionInHigherLayeredPool());
3780 } 3781 }
3781 3782
3782 TEST_F(ClientSocketPoolBaseTest, ForciblyCloseIdleSocketsHeldByLayeredPool) { 3783 TEST_F(ClientSocketPoolBaseTest, ForciblyCloseIdleSocketsHeldByLayeredPool) {
3783 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 3784 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3784 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 3785 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3785 3786
3786 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); 3787 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3787 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); 3788 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3788 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) 3789 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3789 .WillOnce(Invoke(&mock_layered_pool, 3790 .WillOnce(Invoke(&mock_layered_pool,
3790 &MockLayeredPool::ReleaseOneConnection)); 3791 &MockLayeredPool::ReleaseOneConnection));
3791 EXPECT_TRUE(pool_->CloseOneIdleConnectionInLayeredPool()); 3792 EXPECT_TRUE(pool_->CloseOneIdleConnectionInHigherLayeredPool());
3792 } 3793 }
3793 3794
3794 // Tests the basic case of closing an idle socket in a higher layered pool when 3795 // Tests the basic case of closing an idle socket in a higher layered pool when
3795 // a new request is issued and the lower layer pool is stalled. 3796 // a new request is issued and the lower layer pool is stalled.
3796 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) { 3797 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) {
3797 CreatePool(1, 1); 3798 CreatePool(1, 1);
3798 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 3799 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3799 3800
3800 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); 3801 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3801 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); 3802 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
4158 EXPECT_EQ(1, GetOrderOfRequest(5)); 4159 EXPECT_EQ(1, GetOrderOfRequest(5));
4159 EXPECT_EQ(2, GetOrderOfRequest(3)); 4160 EXPECT_EQ(2, GetOrderOfRequest(3));
4160 EXPECT_EQ(3, GetOrderOfRequest(4)); 4161 EXPECT_EQ(3, GetOrderOfRequest(4));
4161 EXPECT_EQ(4, GetOrderOfRequest(1)); 4162 EXPECT_EQ(4, GetOrderOfRequest(1));
4162 EXPECT_EQ(5, GetOrderOfRequest(2)); 4163 EXPECT_EQ(5, GetOrderOfRequest(2));
4163 } 4164 }
4164 4165
4165 } // namespace 4166 } // namespace
4166 4167
4167 } // namespace net 4168 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/socks_client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698