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

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

Issue 1898133002: Add reprioritization to socket pools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated comments. Created 3 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
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/socket_test_util.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 <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 void RequestSockets(const std::string& group_name, 525 void RequestSockets(const std::string& group_name,
526 const void* params, 526 const void* params,
527 int num_sockets, 527 int num_sockets,
528 const NetLogWithSource& net_log) override { 528 const NetLogWithSource& net_log) override {
529 const scoped_refptr<TestSocketParams>* casted_params = 529 const scoped_refptr<TestSocketParams>* casted_params =
530 static_cast<const scoped_refptr<TestSocketParams>*>(params); 530 static_cast<const scoped_refptr<TestSocketParams>*>(params);
531 531
532 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); 532 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log);
533 } 533 }
534 534
535 void SetPriority(const std::string& group_name,
536 ClientSocketHandle* handle,
537 RequestPriority priority) override {
538 base_.SetPriority(group_name, handle, priority);
539 }
540
535 void CancelRequest(const std::string& group_name, 541 void CancelRequest(const std::string& group_name,
536 ClientSocketHandle* handle) override { 542 ClientSocketHandle* handle) override {
537 base_.CancelRequest(group_name, handle); 543 base_.CancelRequest(group_name, handle);
538 } 544 }
539 545
540 void ReleaseSocket(const std::string& group_name, 546 void ReleaseSocket(const std::string& group_name,
541 std::unique_ptr<StreamSocket> socket, 547 std::unique_ptr<StreamSocket> socket,
542 int id) override { 548 int id) override {
543 base_.ReleaseSocket(group_name, std::move(socket), id); 549 base_.ReleaseSocket(group_name, std::move(socket), id);
544 } 550 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 733
728 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { 734 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) {
729 test_base_.ReleaseAllConnections(keep_alive); 735 test_base_.ReleaseAllConnections(keep_alive);
730 } 736 }
731 737
732 TestSocketRequest* request(int i) { return test_base_.request(i); } 738 TestSocketRequest* request(int i) { return test_base_.request(i); }
733 size_t requests_size() const { return test_base_.requests_size(); } 739 size_t requests_size() const { return test_base_.requests_size(); }
734 std::vector<std::unique_ptr<TestSocketRequest>>* requests() { 740 std::vector<std::unique_ptr<TestSocketRequest>>* requests() {
735 return test_base_.requests(); 741 return test_base_.requests();
736 } 742 }
743 // Only counts the requests that get sockets asynchronously;
744 // synchronous completions are not registered by this count.
737 size_t completion_count() const { return test_base_.completion_count(); } 745 size_t completion_count() const { return test_base_.completion_count(); }
738 746
739 TestNetLog net_log_; 747 TestNetLog net_log_;
740 bool connect_backup_jobs_enabled_; 748 bool connect_backup_jobs_enabled_;
741 MockClientSocketFactory client_socket_factory_; 749 MockClientSocketFactory client_socket_factory_;
742 TestConnectJobFactory* connect_job_factory_; 750 TestConnectJobFactory* connect_job_factory_;
743 scoped_refptr<TestSocketParams> params_; 751 scoped_refptr<TestSocketParams> params_;
744 std::unique_ptr<TestClientSocketPool> pool_; 752 std::unique_ptr<TestClientSocketPool> pool_;
745 ClientSocketPoolTest test_base_; 753 ClientSocketPoolTest test_base_;
746 }; 754 };
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 // Request ("b", HIGHEST) has the highest priority, then ("a", MEDIUM), 989 // Request ("b", HIGHEST) has the highest priority, then ("a", MEDIUM),
982 // and then ("c", LOWEST). 990 // and then ("c", LOWEST).
983 EXPECT_EQ(7, GetOrderOfRequest(5)); 991 EXPECT_EQ(7, GetOrderOfRequest(5));
984 EXPECT_EQ(6, GetOrderOfRequest(6)); 992 EXPECT_EQ(6, GetOrderOfRequest(6));
985 EXPECT_EQ(5, GetOrderOfRequest(7)); 993 EXPECT_EQ(5, GetOrderOfRequest(7));
986 994
987 // Make sure we test order of all requests made. 995 // Make sure we test order of all requests made.
988 EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9)); 996 EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(9));
989 } 997 }
990 998
999 // Test reprioritizing a request before completion doesn't interfere with
1000 // its completion.
1001 TEST_F(ClientSocketPoolBaseTest, ReprioritizeOne) {
1002 CreatePool(kDefaultMaxSockets, 1);
1003
1004 EXPECT_THAT(StartRequest("a", LOWEST), IsError(OK));
1005 EXPECT_THAT(StartRequest("a", MEDIUM), IsError(ERR_IO_PENDING));
1006 EXPECT_TRUE(request(0)->handle()->socket());
1007 EXPECT_FALSE(request(1)->handle()->socket());
1008
1009 request(1)->handle()->SetPriority(MEDIUM);
1010
1011 ReleaseOneConnection(ClientSocketPoolTest::NO_KEEP_ALIVE);
1012
1013 EXPECT_TRUE(request(1)->handle()->socket());
1014 }
1015
1016 // Reprioritize a request up past another one and make sure that changes the
1017 // completion order.
1018 TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpReorder) {
1019 CreatePool(kDefaultMaxSockets, 1);
1020
1021 EXPECT_THAT(StartRequest("a", LOWEST), IsError(OK));
1022 EXPECT_THAT(StartRequest("a", MEDIUM), IsError(ERR_IO_PENDING));
1023 EXPECT_THAT(StartRequest("a", LOWEST), IsError(ERR_IO_PENDING));
1024 EXPECT_TRUE(request(0)->handle()->socket());
1025 EXPECT_FALSE(request(1)->handle()->socket());
1026 EXPECT_FALSE(request(2)->handle()->socket());
1027
1028 request(2)->handle()->SetPriority(HIGHEST);
1029
1030 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
1031
1032 EXPECT_EQ(1, GetOrderOfRequest(1));
1033 EXPECT_EQ(3, GetOrderOfRequest(2));
1034 EXPECT_EQ(2, GetOrderOfRequest(3));
1035 }
1036
1037 // Reprioritize a request without changing relative priorities and check
1038 // that the order doesn't change.
1039 TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpNoReorder) {
1040 CreatePool(kDefaultMaxSockets, 1);
1041
1042 EXPECT_THAT(StartRequest("a", LOWEST), IsError(OK));
1043 EXPECT_THAT(StartRequest("a", MEDIUM), IsError(ERR_IO_PENDING));
1044 EXPECT_THAT(StartRequest("a", LOW), IsError(ERR_IO_PENDING));
1045 EXPECT_TRUE(request(0)->handle()->socket());
1046 EXPECT_FALSE(request(1)->handle()->socket());
1047 EXPECT_FALSE(request(2)->handle()->socket());
1048
1049 request(2)->handle()->SetPriority(MEDIUM);
1050
1051 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
1052
1053 EXPECT_EQ(1, GetOrderOfRequest(1));
1054 EXPECT_EQ(2, GetOrderOfRequest(2));
1055 EXPECT_EQ(3, GetOrderOfRequest(3));
1056 }
1057
1058 // Reprioritize a request past down another one and make sure that changes the
1059 // completion order.
1060 TEST_F(ClientSocketPoolBaseTest, ReprioritizeDownReorder) {
1061 CreatePool(kDefaultMaxSockets, 1);
1062
1063 EXPECT_THAT(StartRequest("a", LOWEST), IsError(OK));
1064 EXPECT_THAT(StartRequest("a", HIGHEST), IsError(ERR_IO_PENDING));
1065 EXPECT_THAT(StartRequest("a", MEDIUM), IsError(ERR_IO_PENDING));
1066 EXPECT_TRUE(request(0)->handle()->socket());
1067 EXPECT_FALSE(request(1)->handle()->socket());
1068 EXPECT_FALSE(request(2)->handle()->socket());
1069
1070 request(1)->handle()->SetPriority(LOW);
1071
1072 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
1073
1074 EXPECT_EQ(1, GetOrderOfRequest(1));
1075 EXPECT_EQ(3, GetOrderOfRequest(2));
1076 EXPECT_EQ(2, GetOrderOfRequest(3));
1077 }
1078
1079 // Reprioritize a request to the same level as another and confirm it is
1080 // put after the old request.
1081 TEST_F(ClientSocketPoolBaseTest, ReprioritizeResetFIFO) {
1082 CreatePool(kDefaultMaxSockets, 1);
1083
1084 EXPECT_THAT(StartRequest("a", LOWEST), IsError(OK));
1085 EXPECT_THAT(StartRequest("a", HIGHEST), IsError(ERR_IO_PENDING));
1086 EXPECT_THAT(StartRequest("a", MEDIUM), IsError(ERR_IO_PENDING));
1087 EXPECT_TRUE(request(0)->handle()->socket());
1088 EXPECT_FALSE(request(1)->handle()->socket());
1089 EXPECT_FALSE(request(2)->handle()->socket());
1090
1091 request(1)->handle()->SetPriority(MEDIUM);
1092
1093 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE);
1094
1095 EXPECT_EQ(1, GetOrderOfRequest(1));
1096 EXPECT_EQ(3, GetOrderOfRequest(2));
1097 EXPECT_EQ(2, GetOrderOfRequest(3));
1098 }
1099
991 TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) { 1100 TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) {
992 base::HistogramTester histograms; 1101 base::HistogramTester histograms;
993 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 1102 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
994 1103
995 EXPECT_THAT(StartRequest("a", LOWEST), IsOk()); 1104 EXPECT_THAT(StartRequest("a", LOWEST), IsOk());
996 EXPECT_THAT(StartRequest("a", LOW), IsOk()); 1105 EXPECT_THAT(StartRequest("a", LOW), IsOk());
997 EXPECT_THAT(StartRequest("b", HIGHEST), IsOk()); 1106 EXPECT_THAT(StartRequest("b", HIGHEST), IsOk());
998 EXPECT_THAT(StartRequest("b", MEDIUM), IsOk()); 1107 EXPECT_THAT(StartRequest("b", MEDIUM), IsOk());
999 1108
1000 EXPECT_EQ(static_cast<int>(requests_size()), 1109 EXPECT_EQ(static_cast<int>(requests_size()),
(...skipping 2931 matching lines...) Expand 10 before | Expand all | Expand 10 after
3932 request(1)->handle()->Reset(); 4041 request(1)->handle()->Reset();
3933 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); 4042 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3934 4043
3935 EXPECT_THAT(request(2)->WaitForResult(), IsOk()); 4044 EXPECT_THAT(request(2)->WaitForResult(), IsOk());
3936 EXPECT_FALSE(request(1)->have_result()); 4045 EXPECT_FALSE(request(1)->have_result());
3937 } 4046 }
3938 4047
3939 } // namespace 4048 } // namespace
3940 4049
3941 } // namespace net 4050 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/socket_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698