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

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: Undo somewhat tangential change Created 7 years, 5 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/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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 479
480 class TestClientSocketPool : public ClientSocketPool { 480 class TestClientSocketPool : public ClientSocketPool {
481 public: 481 public:
482 TestClientSocketPool( 482 TestClientSocketPool(
483 int max_sockets, 483 int max_sockets,
484 int max_sockets_per_group, 484 int max_sockets_per_group,
485 ClientSocketPoolHistograms* histograms, 485 ClientSocketPoolHistograms* histograms,
486 base::TimeDelta unused_idle_socket_timeout, 486 base::TimeDelta unused_idle_socket_timeout,
487 base::TimeDelta used_idle_socket_timeout, 487 base::TimeDelta used_idle_socket_timeout,
488 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory) 488 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory)
489 : base_(max_sockets, max_sockets_per_group, histograms, 489 : base_(NULL, max_sockets, max_sockets_per_group, histograms,
490 unused_idle_socket_timeout, used_idle_socket_timeout, 490 unused_idle_socket_timeout, used_idle_socket_timeout,
491 connect_job_factory) {} 491 connect_job_factory) {}
492 492
493 virtual ~TestClientSocketPool() {} 493 virtual ~TestClientSocketPool() {}
494 494
495 virtual int RequestSocket( 495 virtual int RequestSocket(
496 const std::string& group_name, 496 const std::string& group_name,
497 const void* params, 497 const void* params,
498 net::RequestPriority priority, 498 net::RequestPriority priority,
499 ClientSocketHandle* handle, 499 ClientSocketHandle* handle,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 const std::string& group_name) const OVERRIDE { 548 const std::string& group_name) const OVERRIDE {
549 return base_.IdleSocketCountInGroup(group_name); 549 return base_.IdleSocketCountInGroup(group_name);
550 } 550 }
551 551
552 virtual LoadState GetLoadState( 552 virtual LoadState GetLoadState(
553 const std::string& group_name, 553 const std::string& group_name,
554 const ClientSocketHandle* handle) const OVERRIDE { 554 const ClientSocketHandle* handle) const OVERRIDE {
555 return base_.GetLoadState(group_name, handle); 555 return base_.GetLoadState(group_name, handle);
556 } 556 }
557 557
558 virtual void AddLayeredPool(LayeredPool* pool) OVERRIDE { 558 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE {
559 base_.AddLayeredPool(pool); 559 base_.AddHigherLayeredPool(higher_pool);
560 } 560 }
561 561
562 virtual void RemoveLayeredPool(LayeredPool* pool) OVERRIDE { 562 virtual void RemoveHigherLayeredPool(
563 base_.RemoveLayeredPool(pool); 563 HigherLayeredPool* higher_pool) OVERRIDE {
564 base_.RemoveHigherLayeredPool(higher_pool);
564 } 565 }
565 566
566 virtual base::DictionaryValue* GetInfoAsValue( 567 virtual base::DictionaryValue* GetInfoAsValue(
567 const std::string& name, 568 const std::string& name,
568 const std::string& type, 569 const std::string& type,
569 bool include_nested_pools) const OVERRIDE { 570 bool include_nested_pools) const OVERRIDE {
570 return base_.GetInfoAsValue(name, type); 571 return base_.GetInfoAsValue(name, type);
571 } 572 }
572 573
573 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE { 574 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE {
(...skipping 19 matching lines...) Expand all
593 } 594 }
594 595
595 bool HasGroup(const std::string& group_name) const { 596 bool HasGroup(const std::string& group_name) const {
596 return base_.HasGroup(group_name); 597 return base_.HasGroup(group_name);
597 } 598 }
598 599
599 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); } 600 void CleanupTimedOutIdleSockets() { base_.CleanupIdleSockets(false); }
600 601
601 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); } 602 void EnableConnectBackupJobs() { base_.EnableConnectBackupJobs(); }
602 603
603 bool CloseOneIdleConnectionInLayeredPool() { 604 bool CloseOneIdleConnectionInHigherLayeredPool() {
604 return base_.CloseOneIdleConnectionInLayeredPool(); 605 return base_.CloseOneIdleConnectionInHigherLayeredPool();
605 } 606 }
606 607
607 private: 608 private:
608 TestClientSocketPoolBase base_; 609 TestClientSocketPoolBase base_;
609 610
610 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool); 611 DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool);
611 }; 612 };
612 613
613 } // namespace 614 } // namespace
614 615
(...skipping 2948 matching lines...) Expand 10 before | Expand all | Expand 10 after
3563 ASSERT_EQ(OK, callback.WaitForResult()); 3564 ASSERT_EQ(OK, callback.WaitForResult());
3564 3565
3565 // The hung connect job should still be there, but everything else should be 3566 // The hung connect job should still be there, but everything else should be
3566 // complete. 3567 // complete.
3567 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3568 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3568 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a")); 3569 EXPECT_EQ(0, pool_->NumUnassignedConnectJobsInGroup("a"));
3569 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3570 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3570 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a")); 3571 EXPECT_EQ(1, pool_->NumActiveSocketsInGroup("a"));
3571 } 3572 }
3572 3573
3573 class MockLayeredPool : public LayeredPool { 3574 class MockLayeredPool : public HigherLayeredPool {
3574 public: 3575 public:
3575 MockLayeredPool(TestClientSocketPool* pool, 3576 MockLayeredPool(TestClientSocketPool* pool,
3576 const std::string& group_name) 3577 const std::string& group_name)
3577 : pool_(pool), 3578 : pool_(pool),
3578 params_(new TestSocketParams), 3579 params_(new TestSocketParams),
3579 group_name_(group_name), 3580 group_name_(group_name),
3580 can_release_connection_(true) { 3581 can_release_connection_(true) {
3581 pool_->AddLayeredPool(this); 3582 pool_->AddHigherLayeredPool(this);
3582 } 3583 }
3583 3584
3584 ~MockLayeredPool() { 3585 ~MockLayeredPool() {
3585 pool_->RemoveLayeredPool(this); 3586 pool_->RemoveHigherLayeredPool(this);
3586 } 3587 }
3587 3588
3588 int RequestSocket(TestClientSocketPool* pool) { 3589 int RequestSocket(TestClientSocketPool* pool) {
3589 return handle_.Init(group_name_, params_, kDefaultPriority, 3590 return handle_.Init(group_name_, params_, kDefaultPriority,
3590 callback_.callback(), pool, BoundNetLog()); 3591 callback_.callback(), pool, BoundNetLog());
3591 } 3592 }
3592 3593
3593 int RequestSocketWithoutLimits(TestClientSocketPool* pool) { 3594 int RequestSocketWithoutLimits(TestClientSocketPool* pool) {
3594 params_->set_ignore_limits(true); 3595 params_->set_ignore_limits(true);
3595 return handle_.Init(group_name_, params_, kDefaultPriority, 3596 return handle_.Init(group_name_, params_, kDefaultPriority,
(...skipping 25 matching lines...) Expand all
3621 }; 3622 };
3622 3623
3623 TEST_F(ClientSocketPoolBaseTest, FailToCloseIdleSocketsNotHeldByLayeredPool) { 3624 TEST_F(ClientSocketPoolBaseTest, FailToCloseIdleSocketsNotHeldByLayeredPool) {
3624 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 3625 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3625 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 3626 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3626 3627
3627 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); 3628 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3628 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); 3629 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3629 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) 3630 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3630 .WillOnce(Return(false)); 3631 .WillOnce(Return(false));
3631 EXPECT_FALSE(pool_->CloseOneIdleConnectionInLayeredPool()); 3632 EXPECT_FALSE(pool_->CloseOneIdleConnectionInHigherLayeredPool());
3632 } 3633 }
3633 3634
3634 TEST_F(ClientSocketPoolBaseTest, ForciblyCloseIdleSocketsHeldByLayeredPool) { 3635 TEST_F(ClientSocketPoolBaseTest, ForciblyCloseIdleSocketsHeldByLayeredPool) {
3635 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 3636 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
3636 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 3637 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3637 3638
3638 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); 3639 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3639 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); 3640 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
3640 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection()) 3641 EXPECT_CALL(mock_layered_pool, CloseOneIdleConnection())
3641 .WillOnce(Invoke(&mock_layered_pool, 3642 .WillOnce(Invoke(&mock_layered_pool,
3642 &MockLayeredPool::ReleaseOneConnection)); 3643 &MockLayeredPool::ReleaseOneConnection));
3643 EXPECT_TRUE(pool_->CloseOneIdleConnectionInLayeredPool()); 3644 EXPECT_TRUE(pool_->CloseOneIdleConnectionInHigherLayeredPool());
3644 } 3645 }
3645 3646
3646 // Tests the basic case of closing an idle socket in a higher layered pool when 3647 // Tests the basic case of closing an idle socket in a higher layered pool when
3647 // a new request is issued and the lower layer pool is stalled. 3648 // a new request is issued and the lower layer pool is stalled.
3648 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) { 3649 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) {
3649 CreatePool(1, 1); 3650 CreatePool(1, 1);
3650 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 3651 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
3651 3652
3652 MockLayeredPool mock_layered_pool(pool_.get(), "foo"); 3653 MockLayeredPool mock_layered_pool(pool_.get(), "foo");
3653 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get())); 3654 EXPECT_EQ(OK, mock_layered_pool.RequestSocket(pool_.get()));
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
4010 EXPECT_EQ(1, GetOrderOfRequest(5)); 4011 EXPECT_EQ(1, GetOrderOfRequest(5));
4011 EXPECT_EQ(2, GetOrderOfRequest(3)); 4012 EXPECT_EQ(2, GetOrderOfRequest(3));
4012 EXPECT_EQ(3, GetOrderOfRequest(4)); 4013 EXPECT_EQ(3, GetOrderOfRequest(4));
4013 EXPECT_EQ(4, GetOrderOfRequest(1)); 4014 EXPECT_EQ(4, GetOrderOfRequest(1));
4014 EXPECT_EQ(5, GetOrderOfRequest(2)); 4015 EXPECT_EQ(5, GetOrderOfRequest(2));
4015 } 4016 }
4016 4017
4017 } // namespace 4018 } // namespace
4018 4019
4019 } // namespace net 4020 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698