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

Side by Side Diff: net/spdy/spdy_session_unittest.cc

Issue 8230037: Send PING to check the status of the SPDY connection. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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/spdy/spdy_session.cc ('k') | net/spdy/spdy_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) 2011 The Chromium Authors. All rights reserved. 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 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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "net/base/ip_endpoint.h" 7 #include "net/base/ip_endpoint.h"
8 #include "net/spdy/spdy_io_buffer.h" 8 #include "net/spdy/spdy_io_buffer.h"
9 #include "net/spdy/spdy_session_pool.h" 9 #include "net/spdy/spdy_session_pool.h"
10 #include "net/spdy/spdy_stream.h" 10 #include "net/spdy/spdy_stream.h"
11 #include "net/spdy/spdy_test_util.h" 11 #include "net/spdy/spdy_test_util.h"
12 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 // TODO(cbentzel): Expose compression setter/getter in public SpdySession 16 // TODO(cbentzel): Expose compression setter/getter in public SpdySession
17 // interface rather than going through all these contortions. 17 // interface rather than going through all these contortions.
18 class SpdySessionTest : public PlatformTest { 18 class SpdySessionTest : public PlatformTest {
19 public: 19 public:
20 static void TurnOffCompression() { 20 static void TurnOffCompression() {
21 spdy::SpdyFramer::set_enable_compression_default(false); 21 spdy::SpdyFramer::set_enable_compression_default(false);
22 } 22 }
23 protected:
24 virtual void TearDown() {
25 // Wanted to be 100% sure PING is disabled.
26 SpdySession::set_enable_ping_based_connection_checking(false);
27 }
23 }; 28 };
24 29
25 namespace { 30 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate {
31 public:
32 explicit TestSpdyStreamDelegate(OldCompletionCallback* callback)
33 : callback_(callback) {}
34 virtual ~TestSpdyStreamDelegate() {}
35
36 virtual bool OnSendHeadersComplete(int status) { return true; }
37
38 virtual int OnSendBody() {
39 return ERR_UNEXPECTED;
40 }
41
42 virtual int OnSendBodyComplete(int /*status*/, bool* /*eof*/) {
43 return ERR_UNEXPECTED;
44 }
45
46 virtual int OnResponseReceived(const spdy::SpdyHeaderBlock& response,
47 base::Time response_time,
48 int status) {
49 return status;
50 }
51
52 virtual void OnDataReceived(const char* buffer, int bytes) {
53 }
54
55 virtual void OnDataSent(int length) {
56 }
57
58 virtual void OnClose(int status) {
59 OldCompletionCallback* callback = callback_;
60 callback_ = NULL;
61 callback->Run(OK);
62 }
63
64 virtual void set_chunk_callback(net::ChunkCallback *) {}
65
66 private:
67 OldCompletionCallback* callback_;
68 };
69
26 70
27 // Test the SpdyIOBuffer class. 71 // Test the SpdyIOBuffer class.
28 TEST_F(SpdySessionTest, SpdyIOBuffer) { 72 TEST_F(SpdySessionTest, SpdyIOBuffer) {
29 std::priority_queue<SpdyIOBuffer> queue_; 73 std::priority_queue<SpdyIOBuffer> queue_;
30 const size_t kQueueSize = 100; 74 const size_t kQueueSize = 100;
31 75
32 // Insert 100 items; pri 100 to 1. 76 // Insert 100 items; pri 100 to 1.
33 for (size_t index = 0; index < kQueueSize; ++index) { 77 for (size_t index = 0; index < kQueueSize; ++index) {
34 SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL); 78 SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL);
35 queue_.push(buffer); 79 queue_.push(buffer);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 spdy_session_pool->Get(pair, BoundNetLog()); 159 spdy_session_pool->Get(pair, BoundNetLog());
116 160
117 // Delete the first session. 161 // Delete the first session.
118 session = NULL; 162 session = NULL;
119 163
120 // Delete the second session. 164 // Delete the second session.
121 spdy_session_pool->Remove(session2); 165 spdy_session_pool->Remove(session2);
122 session2 = NULL; 166 session2 = NULL;
123 } 167 }
124 168
169 TEST_F(SpdySessionTest, Ping) {
170 SpdySessionDependencies session_deps;
171 session_deps.host_resolver->set_synchronous_mode(true);
172
173 MockConnect connect_data(false, OK);
174 scoped_ptr<spdy::SpdyFrame> read_ping(ConstructSpdyPing());
175 MockRead reads[] = {
176 CreateMockRead(*read_ping),
177 CreateMockRead(*read_ping),
178 MockRead(false, 0, 0) // EOF
179 };
180 scoped_ptr<spdy::SpdyFrame> write_ping(ConstructSpdyPing());
181 MockRead writes[] = {
182 CreateMockRead(*write_ping),
183 CreateMockRead(*write_ping),
184 };
185 StaticSocketDataProvider data(
186 reads, arraysize(reads), writes, arraysize(writes));
187 data.set_connect_data(connect_data);
188 session_deps.socket_factory->AddSocketDataProvider(&data);
189
190 SSLSocketDataProvider ssl(false, OK);
191 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
192
193 scoped_refptr<HttpNetworkSession> http_session(
194 SpdySessionDependencies::SpdyCreateSession(&session_deps));
195
196 static const char kStreamUrl[] = "http://www.google.com/";
197 GURL url(kStreamUrl);
198
199 const std::string kTestHost("www.google.com");
200 const int kTestPort = 80;
201 HostPortPair test_host_port_pair(kTestHost, kTestPort);
202 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
203
204 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
205 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
206 scoped_refptr<SpdySession> session =
207 spdy_session_pool->Get(pair, BoundNetLog());
208 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
209
210
211 scoped_refptr<TransportSocketParams> transport_params(
212 new TransportSocketParams(test_host_port_pair,
213 MEDIUM,
214 GURL(),
215 false,
216 false));
217 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
218 EXPECT_EQ(OK,
219 connection->Init(test_host_port_pair.ToString(),
220 transport_params,
221 MEDIUM,
222 NULL,
223 http_session->transport_socket_pool(),
224 BoundNetLog()));
225 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
226
227 scoped_refptr<SpdyStream> spdy_stream1;
228 TestOldCompletionCallback callback1;
229 EXPECT_EQ(OK, session->CreateStream(url,
230 MEDIUM,
231 &spdy_stream1,
232 BoundNetLog(),
233 &callback1));
234 scoped_ptr<TestSpdyStreamDelegate> delegate(
235 new TestSpdyStreamDelegate(&callback1));
236 spdy_stream1->SetDelegate(delegate.get());
237
238 base::TimeTicks before_ping_time = base::TimeTicks::Now();
239
240 // Enable sending of PING.
241 SpdySession::set_enable_ping_based_connection_checking(true);
242 SpdySession::set_connection_at_risk_of_loss_ms(0);
243 SpdySession::set_trailing_ping_delay_time_ms(0);
244 SpdySession::set_hung_interval_ms(50);
245
246 session->SendPrefacePingIfNoneInFlight();
247
248 EXPECT_EQ(OK, callback1.WaitForResult());
249
250 EXPECT_EQ(0, session->pings_in_flight());
251 EXPECT_GT(session->next_ping_id(), static_cast<uint32>(1));
252 EXPECT_FALSE(session->trailing_ping_pending());
253 // TODO(rtenneti): check_ping_status_pending works in debug mode with
254 // breakpoints, but fails if run in stand alone mode.
255 // EXPECT_FALSE(session->check_ping_status_pending());
256 EXPECT_GE(session->received_data_time(), before_ping_time);
257
258 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
259
260 // Delete the first session.
261 session = NULL;
262 }
263
125 class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > { 264 class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > {
126 public: 265 public:
127 StreamReleaserCallback(SpdySession* session, 266 StreamReleaserCallback(SpdySession* session,
128 SpdyStream* first_stream) 267 SpdyStream* first_stream)
129 : session_(session), first_stream_(first_stream) {} 268 : session_(session), first_stream_(first_stream) {}
130 ~StreamReleaserCallback() {} 269 ~StreamReleaserCallback() {}
131 270
132 int WaitForResult() { return callback_.WaitForResult(); } 271 int WaitForResult() { return callback_.WaitForResult(); }
133 272
134 virtual void RunWithParams(const Tuple1<int>& params) { 273 virtual void RunWithParams(const Tuple1<int>& params) {
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 const size_t max_concurrent_streams = 2; 815 const size_t max_concurrent_streams = 2;
677 spdy::SpdySettings test_settings; 816 spdy::SpdySettings test_settings;
678 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); 817 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams));
679 818
680 test_settings_storage->Set(test_host_port_pair, test_settings); 819 test_settings_storage->Set(test_host_port_pair, test_settings);
681 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size()); 820 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size());
682 spdy_session_pool->OnIPAddressChanged(); 821 spdy_session_pool->OnIPAddressChanged();
683 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); 822 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size());
684 } 823 }
685 824
686 } // namespace
687
688 } // namespace net 825 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698