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

Side by Side Diff: net/http/http_pipelined_host_pool_unittest.cc

Issue 9433015: Add a force pipelining option to load flags. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add backup buffer 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
OLDNEW
1 // Copyright (c) 2011 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/http/http_pipelined_host_pool.h" 5 #include "net/http/http_pipelined_host_pool.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h"
8 #include "net/base/ssl_config_service.h" 9 #include "net/base/ssl_config_service.h"
9 #include "net/http/http_pipelined_host.h" 10 #include "net/http/http_pipelined_host.h"
10 #include "net/http/http_pipelined_host_capability.h" 11 #include "net/http/http_pipelined_host_capability.h"
11 #include "net/http/http_server_properties_impl.h" 12 #include "net/http/http_server_properties_impl.h"
12 #include "net/proxy/proxy_info.h" 13 #include "net/proxy/proxy_info.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 using testing::_; 17 using testing::_;
17 using testing::Ref; 18 using testing::Ref;
18 using testing::Return; 19 using testing::Return;
19 using testing::ReturnNull; 20 using testing::ReturnNull;
20 21
21 namespace net { 22 namespace net {
22 23
23 namespace { 24 namespace {
24 25
25 ClientSocketHandle* kDummyConnection = 26 ClientSocketHandle* kDummyConnection =
26 reinterpret_cast<ClientSocketHandle*>(188); 27 reinterpret_cast<ClientSocketHandle*>(188);
27 HttpPipelinedStream* kDummyStream = 28 HttpPipelinedStream* kDummyStream =
28 reinterpret_cast<HttpPipelinedStream*>(99); 29 reinterpret_cast<HttpPipelinedStream*>(99);
29 30
30 class MockPoolDelegate : public HttpPipelinedHostPool::Delegate { 31 class MockPoolDelegate : public HttpPipelinedHostPool::Delegate {
31 public: 32 public:
32 MOCK_METHOD1(OnHttpPipelinedHostHasAdditionalCapacity, 33 MOCK_METHOD1(OnHttpPipelinedHostHasAdditionalCapacity,
33 void(const HostPortPair& origin)); 34 void(HttpPipelinedHost* host));
34 }; 35 };
35 36
36 class MockHostFactory : public HttpPipelinedHost::Factory { 37 class MockHostFactory : public HttpPipelinedHost::Factory {
37 public: 38 public:
38 MOCK_METHOD4(CreateNewHost, HttpPipelinedHost*( 39 MOCK_METHOD4(CreateNewHost, HttpPipelinedHost*(
39 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, 40 HttpPipelinedHost::Delegate* delegate,
41 const HttpPipelinedHost::Key& key,
40 HttpPipelinedConnection::Factory* factory, 42 HttpPipelinedConnection::Factory* factory,
41 HttpPipelinedHostCapability capability)); 43 HttpPipelinedHostCapability capability));
42 }; 44 };
43 45
44 class MockHost : public HttpPipelinedHost { 46 class MockHost : public HttpPipelinedHost {
45 public: 47 public:
46 MockHost(const HostPortPair& origin) 48 MockHost(const Key& key)
47 : origin_(origin) { 49 : key_(key) {
48 } 50 }
49 51
50 MOCK_METHOD6(CreateStreamOnNewPipeline, HttpPipelinedStream*( 52 MOCK_METHOD6(CreateStreamOnNewPipeline, HttpPipelinedStream*(
51 ClientSocketHandle* connection, 53 ClientSocketHandle* connection,
52 const SSLConfig& used_ssl_config, 54 const SSLConfig& used_ssl_config,
53 const ProxyInfo& used_proxy_info, 55 const ProxyInfo& used_proxy_info,
54 const BoundNetLog& net_log, 56 const BoundNetLog& net_log,
55 bool was_npn_negotiated, 57 bool was_npn_negotiated,
56 SSLClientSocket::NextProto protocol_negotiated)); 58 SSLClientSocket::NextProto protocol_negotiated));
57 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*()); 59 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*());
58 MOCK_CONST_METHOD0(IsExistingPipelineAvailable, bool()); 60 MOCK_CONST_METHOD0(IsExistingPipelineAvailable, bool());
59 MOCK_CONST_METHOD0(PipelineInfoToValue, base::Value*()); 61 MOCK_CONST_METHOD0(PipelineInfoToValue, base::Value*());
60 62
61 virtual const HostPortPair& origin() const OVERRIDE { return origin_; } 63 virtual const Key& GetKey() const OVERRIDE { return key_; }
62 64
63 private: 65 private:
64 HostPortPair origin_; 66 Key key_;
65 }; 67 };
66 68
67 class HttpPipelinedHostPoolTest : public testing::Test { 69 class HttpPipelinedHostPoolTest : public testing::Test {
68 public: 70 public:
69 HttpPipelinedHostPoolTest() 71 HttpPipelinedHostPoolTest()
70 : origin_("host", 123), 72 : key_(HostPortPair("host", 123), false),
71 factory_(new MockHostFactory), // Owned by pool_. 73 factory_(new MockHostFactory), // Owned by pool_.
72 host_(new MockHost(origin_)), // Owned by pool_. 74 host_(new MockHost(key_)), // Owned by pool_.
73 http_server_properties_(new HttpServerPropertiesImpl), 75 http_server_properties_(new HttpServerPropertiesImpl),
74 pool_(new HttpPipelinedHostPool(&delegate_, factory_, 76 pool_(new HttpPipelinedHostPool(&delegate_, factory_,
75 http_server_properties_.get())), 77 http_server_properties_.get())),
76 was_npn_negotiated_(false), 78 was_npn_negotiated_(false),
77 protocol_negotiated_(SSLClientSocket::kProtoUnknown) { 79 protocol_negotiated_(SSLClientSocket::kProtoUnknown) {
78 } 80 }
79 81
80 void CreateDummyStream() { 82 void CreateDummyStream(const HttpPipelinedHost::Key& key,
81 EXPECT_CALL(*host_, CreateStreamOnNewPipeline(kDummyConnection, 83 ClientSocketHandle* connection,
82 Ref(ssl_config_), 84 HttpPipelinedStream* stream,
83 Ref(proxy_info_), 85 MockHost* host) {
84 Ref(net_log_), 86 EXPECT_CALL(*host, CreateStreamOnNewPipeline(connection,
85 was_npn_negotiated_, 87 Ref(ssl_config_),
86 protocol_negotiated_)) 88 Ref(proxy_info_),
89 Ref(net_log_),
90 was_npn_negotiated_,
91 protocol_negotiated_))
87 .Times(1) 92 .Times(1)
88 .WillOnce(Return(kDummyStream)); 93 .WillOnce(Return(stream));
89 EXPECT_EQ(kDummyStream, 94 EXPECT_EQ(stream,
90 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, 95 pool_->CreateStreamOnNewPipeline(key, connection,
91 ssl_config_, proxy_info_, 96 ssl_config_, proxy_info_,
92 net_log_, was_npn_negotiated_, 97 net_log_, was_npn_negotiated_,
93 protocol_negotiated_)); 98 protocol_negotiated_));
94 } 99 }
95 100
96 HostPortPair origin_; 101 MockHost* CreateDummyHost(const HttpPipelinedHost::Key& key) {
102 MockHost* mock_host = new MockHost(key);
103 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key), _,
104 PIPELINE_UNKNOWN))
105 .Times(1)
106 .WillOnce(Return(mock_host));
107 ClientSocketHandle* dummy_connection =
108 reinterpret_cast<ClientSocketHandle*>(base::RandUint64());
109 HttpPipelinedStream* dummy_stream =
110 reinterpret_cast<HttpPipelinedStream*>(base::RandUint64());
111 CreateDummyStream(key, dummy_connection, dummy_stream, mock_host);
112 return mock_host;
113 }
114
115 HttpPipelinedHost::Key key_;
97 MockPoolDelegate delegate_; 116 MockPoolDelegate delegate_;
98 MockHostFactory* factory_; 117 MockHostFactory* factory_;
99 MockHost* host_; 118 MockHost* host_;
100 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_; 119 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_;
101 scoped_ptr<HttpPipelinedHostPool> pool_; 120 scoped_ptr<HttpPipelinedHostPool> pool_;
102 121
103 const SSLConfig ssl_config_; 122 const SSLConfig ssl_config_;
104 const ProxyInfo proxy_info_; 123 const ProxyInfo proxy_info_;
105 const BoundNetLog net_log_; 124 const BoundNetLog net_log_;
106 bool was_npn_negotiated_; 125 bool was_npn_negotiated_;
107 SSLClientSocket::NextProto protocol_negotiated_; 126 SSLClientSocket::NextProto protocol_negotiated_;
108 }; 127 };
109 128
110 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) { 129 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) {
111 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); 130 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_));
112 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 131 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
113 PIPELINE_UNKNOWN)) 132 PIPELINE_UNKNOWN))
114 .Times(1) 133 .Times(1)
115 .WillOnce(Return(host_)); 134 .WillOnce(Return(host_));
116 135
117 CreateDummyStream(); 136 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_);
118 pool_->OnHostIdle(host_); 137 pool_->OnHostIdle(host_);
119 } 138 }
120 139
121 TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) { 140 TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) {
122 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 141 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
123 PIPELINE_UNKNOWN)) 142 PIPELINE_UNKNOWN))
124 .Times(1) 143 .Times(1)
125 .WillOnce(Return(host_)); 144 .WillOnce(Return(host_));
126 145
127 CreateDummyStream(); 146 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_);
128 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE); 147 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE);
129 pool_->OnHostIdle(host_); 148 pool_->OnHostIdle(host_);
130 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); 149 EXPECT_FALSE(pool_->IsKeyEligibleForPipelining(key_));
131 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 150 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
132 PIPELINE_INCAPABLE)) 151 PIPELINE_INCAPABLE))
133 .Times(0); 152 .Times(0);
134 EXPECT_EQ(NULL, 153 EXPECT_EQ(NULL,
135 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, 154 pool_->CreateStreamOnNewPipeline(key_, kDummyConnection,
136 ssl_config_, proxy_info_, net_log_, 155 ssl_config_, proxy_info_, net_log_,
137 was_npn_negotiated_, 156 was_npn_negotiated_,
138 protocol_negotiated_)); 157 protocol_negotiated_));
139 } 158 }
140 159
141 TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) { 160 TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) {
142 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 161 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
143 PIPELINE_UNKNOWN)) 162 PIPELINE_UNKNOWN))
144 .Times(1) 163 .Times(1)
145 .WillOnce(Return(host_)); 164 .WillOnce(Return(host_));
146 165
147 CreateDummyStream(); 166 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_);
148 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 167 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
149 pool_->OnHostIdle(host_); 168 pool_->OnHostIdle(host_);
150 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); 169 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_));
151 170
152 host_ = new MockHost(origin_); 171 host_ = new MockHost(key_);
153 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 172 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
154 PIPELINE_CAPABLE)) 173 PIPELINE_CAPABLE))
155 .Times(1) 174 .Times(1)
156 .WillOnce(Return(host_)); 175 .WillOnce(Return(host_));
157 CreateDummyStream(); 176 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_);
158 pool_->OnHostIdle(host_); 177 pool_->OnHostIdle(host_);
159 } 178 }
160 179
161 TEST_F(HttpPipelinedHostPoolTest, IncapableIsSticky) { 180 TEST_F(HttpPipelinedHostPoolTest, IncapableIsSticky) {
162 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 181 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
163 PIPELINE_UNKNOWN)) 182 PIPELINE_UNKNOWN))
164 .Times(1) 183 .Times(1)
165 .WillOnce(Return(host_)); 184 .WillOnce(Return(host_));
166 185
167 CreateDummyStream(); 186 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_);
168 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 187 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
169 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE); 188 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE);
170 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 189 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
171 pool_->OnHostIdle(host_); 190 pool_->OnHostIdle(host_);
172 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); 191 EXPECT_FALSE(pool_->IsKeyEligibleForPipelining(key_));
173 } 192 }
174 193
175 TEST_F(HttpPipelinedHostPoolTest, RemainsUnknownWithoutFeedback) { 194 TEST_F(HttpPipelinedHostPoolTest, RemainsUnknownWithoutFeedback) {
176 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 195 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
177 PIPELINE_UNKNOWN)) 196 PIPELINE_UNKNOWN))
178 .Times(1) 197 .Times(1)
179 .WillOnce(Return(host_)); 198 .WillOnce(Return(host_));
180 199
181 CreateDummyStream(); 200 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_);
182 pool_->OnHostIdle(host_); 201 pool_->OnHostIdle(host_);
183 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); 202 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_));
184 203
185 host_ = new MockHost(origin_); 204 host_ = new MockHost(key_);
186 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 205 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
187 PIPELINE_UNKNOWN)) 206 PIPELINE_UNKNOWN))
188 .Times(1) 207 .Times(1)
189 .WillOnce(Return(host_)); 208 .WillOnce(Return(host_));
190 209
191 CreateDummyStream(); 210 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_);
192 pool_->OnHostIdle(host_); 211 pool_->OnHostIdle(host_);
193 } 212 }
194 213
195 TEST_F(HttpPipelinedHostPoolTest, PopulatesServerProperties) { 214 TEST_F(HttpPipelinedHostPoolTest, PopulatesServerProperties) {
196 EXPECT_EQ(PIPELINE_UNKNOWN, 215 EXPECT_EQ(PIPELINE_UNKNOWN,
197 http_server_properties_->GetPipelineCapability(host_->origin())); 216 http_server_properties_->GetPipelineCapability(
217 host_->GetKey().origin()));
198 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 218 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
199 EXPECT_EQ(PIPELINE_CAPABLE, 219 EXPECT_EQ(PIPELINE_CAPABLE,
200 http_server_properties_->GetPipelineCapability(host_->origin())); 220 http_server_properties_->GetPipelineCapability(
221 host_->GetKey().origin()));
201 delete host_; // Must manually delete, because it's never added to |pool_|. 222 delete host_; // Must manually delete, because it's never added to |pool_|.
202 } 223 }
203 224
225 TEST_F(HttpPipelinedHostPoolTest, MultipleKeys) {
226 HttpPipelinedHost::Key key1(HostPortPair("host", 123), false);
227 HttpPipelinedHost::Key key2(HostPortPair("host", 123), true);
228 HttpPipelinedHost::Key key3(HostPortPair("host", 456), false);
229 HttpPipelinedHost::Key key4(HostPortPair("other", 456), false);
230 HttpPipelinedHost::Key key5(HostPortPair("other", 789), true);
231 MockHost* host1 = CreateDummyHost(key1);
232 MockHost* host2 = CreateDummyHost(key2);
233 MockHost* host3 = CreateDummyHost(key3);
234 MockHost* host4 = CreateDummyHost(key4);
235
236 EXPECT_CALL(*host1, IsExistingPipelineAvailable())
237 .Times(1)
238 .WillOnce(Return(true));
239 EXPECT_EQ(true, pool_->IsExistingPipelineAvailableForKey(key1));
240
241 EXPECT_CALL(*host2, IsExistingPipelineAvailable())
242 .Times(1)
243 .WillOnce(Return(false));
244 EXPECT_EQ(false, pool_->IsExistingPipelineAvailableForKey(key2));
245
246 EXPECT_CALL(*host3, IsExistingPipelineAvailable())
247 .Times(1)
248 .WillOnce(Return(true));
249 EXPECT_EQ(true, pool_->IsExistingPipelineAvailableForKey(key3));
250
251 EXPECT_CALL(*host4, IsExistingPipelineAvailable())
252 .Times(1)
253 .WillOnce(Return(false));
254 EXPECT_EQ(false, pool_->IsExistingPipelineAvailableForKey(key4));
255
256 EXPECT_EQ(false, pool_->IsExistingPipelineAvailableForKey(key5));
257
258 pool_->OnHostIdle(host1);
259 pool_->OnHostIdle(host2);
260 pool_->OnHostIdle(host3);
261 pool_->OnHostIdle(host4);
262 }
263
204 } // anonymous namespace 264 } // anonymous namespace
205 265
206 } // namespace net 266 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698