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

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

Issue 8586015: Slow start pipelining. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for landing Created 9 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/http/http_pipelined_host_impl.cc ('k') | net/http/http_pipelined_host_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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/http/http_pipelined_host_impl.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "net/base/ssl_config_service.h"
9 #include "net/http/http_pipelined_connection.h"
10 #include "net/proxy/proxy_info.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using testing::_;
15 using testing::NiceMock;
16 using testing::Ref;
17 using testing::Return;
18 using testing::ReturnNull;
19
20 namespace net {
21
22 namespace {
23
24 ClientSocketHandle* kDummyConnection =
25 reinterpret_cast<ClientSocketHandle*>(84);
26 HttpPipelinedStream* kDummyStream =
27 reinterpret_cast<HttpPipelinedStream*>(42);
28
29 class MockHostDelegate : public HttpPipelinedHost::Delegate {
30 public:
31 MOCK_METHOD1(OnHostIdle, void(HttpPipelinedHost* host));
32 MOCK_METHOD1(OnHostHasAdditionalCapacity, void(HttpPipelinedHost* host));
33 MOCK_METHOD2(OnHostDeterminedCapability,
34 void(HttpPipelinedHost* host,
35 HttpPipelinedHost::Capability capability));
36 };
37
38 class MockPipelineFactory : public HttpPipelinedConnection::Factory {
39 public:
40 MOCK_METHOD6(CreateNewPipeline, HttpPipelinedConnection*(
41 ClientSocketHandle* connection,
42 HttpPipelinedConnection::Delegate* delegate,
43 const SSLConfig& used_ssl_config,
44 const ProxyInfo& used_proxy_info,
45 const BoundNetLog& net_log,
46 bool was_npn_negotiated));
47 };
48
49 class MockPipeline : public HttpPipelinedConnection {
50 public:
51 MockPipeline(int depth, bool usable, bool active)
52 : depth_(depth),
53 usable_(usable),
54 active_(active) {
55 }
56
57 void SetState(int depth, bool usable, bool active) {
58 depth_ = depth;
59 usable_ = usable;
60 active_ = active;
61 }
62
63 virtual int depth() const OVERRIDE { return depth_; }
64 virtual bool usable() const OVERRIDE { return usable_; }
65 virtual bool active() const OVERRIDE { return active_; }
66
67 MOCK_METHOD0(CreateNewStream, HttpPipelinedStream*());
68 MOCK_METHOD1(OnStreamDeleted, void(int pipeline_id));
69 MOCK_CONST_METHOD0(used_ssl_config, const SSLConfig&());
70 MOCK_CONST_METHOD0(used_proxy_info, const ProxyInfo&());
71 MOCK_CONST_METHOD0(source, const NetLog::Source&());
72 MOCK_CONST_METHOD0(was_npn_negotiated, bool());
73
74 private:
75 int depth_;
76 bool usable_;
77 bool active_;
78 };
79
80 class HttpPipelinedHostImplTest : public testing::Test {
81 public:
82 HttpPipelinedHostImplTest()
83 : origin_("host", 123),
84 factory_(new MockPipelineFactory), // Owned by host_.
85 host_(new HttpPipelinedHostImpl(&delegate_, origin_, factory_,
86 HttpPipelinedHost::CAPABLE)) {
87 }
88
89 void SetCapability(HttpPipelinedHost::Capability capability) {
90 factory_ = new MockPipelineFactory;
91 host_.reset(new HttpPipelinedHostImpl(
92 &delegate_, origin_, factory_, capability));
93 }
94
95 MockPipeline* AddTestPipeline(int depth, bool usable, bool active) {
96 MockPipeline* pipeline = new MockPipeline(depth, usable, active);
97 EXPECT_CALL(*factory_, CreateNewPipeline(kDummyConnection, host_.get(),
98 Ref(ssl_config_), Ref(proxy_info_),
99 Ref(net_log_), true))
100 .Times(1)
101 .WillOnce(Return(pipeline));
102 EXPECT_CALL(*pipeline, CreateNewStream())
103 .Times(1)
104 .WillOnce(Return(kDummyStream));
105 EXPECT_EQ(kDummyStream, host_->CreateStreamOnNewPipeline(
106 kDummyConnection, ssl_config_, proxy_info_, net_log_, true));
107 return pipeline;
108 }
109
110 void ClearTestPipeline(MockPipeline* pipeline) {
111 pipeline->SetState(0, true, true);
112 host_->OnPipelineHasCapacity(pipeline);
113 }
114
115 NiceMock<MockHostDelegate> delegate_;
116 HostPortPair origin_;
117 MockPipelineFactory* factory_;
118 scoped_ptr<HttpPipelinedHostImpl> host_;
119
120 SSLConfig ssl_config_;
121 ProxyInfo proxy_info_;
122 BoundNetLog net_log_;
123 };
124
125 TEST_F(HttpPipelinedHostImplTest, Delegate) {
126 EXPECT_TRUE(origin_.Equals(host_->origin()));
127 }
128
129 TEST_F(HttpPipelinedHostImplTest, OnUnusablePipelineHasCapacity) {
130 MockPipeline* pipeline = AddTestPipeline(0, false, true);
131
132 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
133 .Times(0);
134 EXPECT_CALL(delegate_, OnHostIdle(host_.get()))
135 .Times(1);
136 host_->OnPipelineHasCapacity(pipeline);
137 }
138
139 TEST_F(HttpPipelinedHostImplTest, OnUsablePipelineHasCapacity) {
140 MockPipeline* pipeline = AddTestPipeline(1, true, true);
141
142 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
143 .Times(1);
144 EXPECT_CALL(delegate_, OnHostIdle(host_.get()))
145 .Times(0);
146
147 host_->OnPipelineHasCapacity(pipeline);
148
149 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
150 .Times(1);
151 EXPECT_CALL(delegate_, OnHostIdle(host_.get()))
152 .Times(1);
153 ClearTestPipeline(pipeline);
154 }
155
156 TEST_F(HttpPipelinedHostImplTest, IgnoresUnusablePipeline) {
157 MockPipeline* pipeline = AddTestPipeline(1, false, true);
158
159 EXPECT_FALSE(host_->IsExistingPipelineAvailable());
160 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
161
162 ClearTestPipeline(pipeline);
163 }
164
165 TEST_F(HttpPipelinedHostImplTest, IgnoresInactivePipeline) {
166 MockPipeline* pipeline = AddTestPipeline(1, true, false);
167
168 EXPECT_FALSE(host_->IsExistingPipelineAvailable());
169 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
170
171 ClearTestPipeline(pipeline);
172 }
173
174 TEST_F(HttpPipelinedHostImplTest, IgnoresFullPipeline) {
175 MockPipeline* pipeline = AddTestPipeline(
176 HttpPipelinedHostImpl::max_pipeline_depth(), true, true);
177
178 EXPECT_FALSE(host_->IsExistingPipelineAvailable());
179 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
180
181 ClearTestPipeline(pipeline);
182 }
183
184 TEST_F(HttpPipelinedHostImplTest, PicksLeastLoadedPipeline) {
185 MockPipeline* full_pipeline = AddTestPipeline(
186 HttpPipelinedHostImpl::max_pipeline_depth(), true, true);
187 MockPipeline* usable_pipeline = AddTestPipeline(
188 HttpPipelinedHostImpl::max_pipeline_depth() - 1, true, true);
189 MockPipeline* empty_pipeline = AddTestPipeline(0, true, true);
190
191 EXPECT_TRUE(host_->IsExistingPipelineAvailable());
192 EXPECT_CALL(*empty_pipeline, CreateNewStream())
193 .Times(1)
194 .WillOnce(ReturnNull());
195 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
196
197 ClearTestPipeline(full_pipeline);
198 ClearTestPipeline(usable_pipeline);
199 ClearTestPipeline(empty_pipeline);
200 }
201
202 TEST_F(HttpPipelinedHostImplTest, OpensUpOnPipelineSuccess) {
203 SetCapability(HttpPipelinedHost::UNKNOWN);
204 MockPipeline* pipeline = AddTestPipeline(1, true, true);
205
206 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
207 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
208 .Times(1);
209 host_->OnPipelineFeedback(pipeline, HttpPipelinedConnection::OK);
210
211 EXPECT_CALL(*pipeline, CreateNewStream())
212 .Times(1)
213 .WillOnce(Return(kDummyStream));
214 EXPECT_EQ(kDummyStream, host_->CreateStreamOnExistingPipeline());
215
216 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
217 .Times(1);
218 ClearTestPipeline(pipeline);
219 }
220
221 TEST_F(HttpPipelinedHostImplTest, OpensAllPipelinesOnPipelineSuccess) {
222 SetCapability(HttpPipelinedHost::UNKNOWN);
223 MockPipeline* pipeline1 = AddTestPipeline(1, false, true);
224 MockPipeline* pipeline2 = AddTestPipeline(1, true, true);
225
226 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
227 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
228 .Times(1);
229 host_->OnPipelineFeedback(pipeline1, HttpPipelinedConnection::OK);
230
231 EXPECT_CALL(*pipeline2, CreateNewStream())
232 .Times(1)
233 .WillOnce(Return(kDummyStream));
234 EXPECT_EQ(kDummyStream, host_->CreateStreamOnExistingPipeline());
235
236 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
237 .Times(2);
238 ClearTestPipeline(pipeline1);
239 ClearTestPipeline(pipeline2);
240 }
241
242 TEST_F(HttpPipelinedHostImplTest, ShutsDownOnOldVersion) {
243 SetCapability(HttpPipelinedHost::UNKNOWN);
244 MockPipeline* pipeline = AddTestPipeline(1, true, true);
245
246 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
247 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
248 .Times(0);
249 EXPECT_CALL(delegate_,
250 OnHostDeterminedCapability(host_.get(),
251 HttpPipelinedHost::INCAPABLE))
252 .Times(1);
253 host_->OnPipelineFeedback(pipeline,
254 HttpPipelinedConnection::OLD_HTTP_VERSION);
255
256 ClearTestPipeline(pipeline);
257 EXPECT_EQ(NULL, host_->CreateStreamOnNewPipeline(
258 kDummyConnection, ssl_config_, proxy_info_, net_log_, true));
259 }
260
261 TEST_F(HttpPipelinedHostImplTest, ConnectionCloseHasNoEffect) {
262 SetCapability(HttpPipelinedHost::UNKNOWN);
263 MockPipeline* pipeline = AddTestPipeline(1, true, true);
264
265 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
266 .Times(0);
267 EXPECT_CALL(delegate_, OnHostDeterminedCapability(host_.get(), _))
268 .Times(0);
269 host_->OnPipelineFeedback(pipeline,
270 HttpPipelinedConnection::MUST_CLOSE_CONNECTION);
271 EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline());
272
273 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
274 .Times(1);
275 ClearTestPipeline(pipeline);
276 }
277
278 TEST_F(HttpPipelinedHostImplTest, SuccessesLeadToCapable) {
279 SetCapability(HttpPipelinedHost::UNKNOWN);
280 MockPipeline* pipeline = AddTestPipeline(1, true, true);
281
282 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
283 .Times(1);
284 EXPECT_CALL(delegate_,
285 OnHostDeterminedCapability(host_.get(),
286 HttpPipelinedHost::CAPABLE))
287 .Times(1);
288 host_->OnPipelineFeedback(pipeline, HttpPipelinedConnection::OK);
289
290 pipeline->SetState(3, true, true);
291 host_->OnPipelineFeedback(pipeline, HttpPipelinedConnection::OK);
292 host_->OnPipelineFeedback(pipeline, HttpPipelinedConnection::OK);
293
294 EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get()))
295 .Times(1);
296 ClearTestPipeline(pipeline);
297 }
298
299 } // anonymous namespace
300
301 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_pipelined_host_impl.cc ('k') | net/http/http_pipelined_host_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698