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

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

Issue 8369023: Unittest for SPDY's Failed Ping (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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.h ('k') | no next file » | 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"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // Enable sending of PING. 240 // Enable sending of PING.
241 SpdySession::set_enable_ping_based_connection_checking(true); 241 SpdySession::set_enable_ping_based_connection_checking(true);
242 SpdySession::set_connection_at_risk_of_loss_ms(0); 242 SpdySession::set_connection_at_risk_of_loss_ms(0);
243 SpdySession::set_trailing_ping_delay_time_ms(0); 243 SpdySession::set_trailing_ping_delay_time_ms(0);
244 SpdySession::set_hung_interval_ms(50); 244 SpdySession::set_hung_interval_ms(50);
245 245
246 session->SendPrefacePingIfNoneInFlight(); 246 session->SendPrefacePingIfNoneInFlight();
247 247
248 EXPECT_EQ(OK, callback1.WaitForResult()); 248 EXPECT_EQ(OK, callback1.WaitForResult());
249 249
250 session->CheckPingStatus(before_ping_time);
251
250 EXPECT_EQ(0, session->pings_in_flight()); 252 EXPECT_EQ(0, session->pings_in_flight());
251 EXPECT_GT(session->next_ping_id(), static_cast<uint32>(1)); 253 EXPECT_GT(session->next_ping_id(), static_cast<uint32>(1));
252 EXPECT_FALSE(session->trailing_ping_pending()); 254 EXPECT_FALSE(session->trailing_ping_pending());
253 // TODO(rtenneti): check_ping_status_pending works in debug mode with 255 EXPECT_FALSE(session->check_ping_status_pending());
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); 256 EXPECT_GE(session->received_data_time(), before_ping_time);
257 257
258 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 258 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
259 259
260 // Delete the first session. 260 // Delete the first session.
261 session = NULL; 261 session = NULL;
262 } 262 }
263 263
264 TEST_F(SpdySessionTest, FailedPing) {
265 SpdySessionDependencies session_deps;
266 session_deps.host_resolver->set_synchronous_mode(true);
267
268 MockConnect connect_data(false, OK);
269 scoped_ptr<spdy::SpdyFrame> read_ping(ConstructSpdyPing());
270 MockRead reads[] = {
271 CreateMockRead(*read_ping),
272 MockRead(false, 0, 0) // EOF
273 };
274 scoped_ptr<spdy::SpdyFrame> write_ping(ConstructSpdyPing());
275 MockRead writes[] = {
276 CreateMockRead(*write_ping),
277 };
278 StaticSocketDataProvider data(
279 reads, arraysize(reads), writes, arraysize(writes));
280 data.set_connect_data(connect_data);
281 session_deps.socket_factory->AddSocketDataProvider(&data);
282
283 SSLSocketDataProvider ssl(false, OK);
284 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
285
286 scoped_refptr<HttpNetworkSession> http_session(
287 SpdySessionDependencies::SpdyCreateSession(&session_deps));
288
289 static const char kStreamUrl[] = "http://www.gmail.com/";
290 GURL url(kStreamUrl);
291
292 const std::string kTestHost("www.gmail.com");
293 const int kTestPort = 80;
294 HostPortPair test_host_port_pair(kTestHost, kTestPort);
295 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
296
297 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
298 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
299 scoped_refptr<SpdySession> session =
300 spdy_session_pool->Get(pair, BoundNetLog());
301 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
302
303 scoped_refptr<TransportSocketParams> transport_params(
304 new TransportSocketParams(test_host_port_pair,
305 MEDIUM,
306 GURL(),
307 false,
308 false));
309 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
310 EXPECT_EQ(OK,
311 connection->Init(test_host_port_pair.ToString(),
312 transport_params,
313 MEDIUM,
314 NULL,
315 http_session->transport_socket_pool(),
316 BoundNetLog()));
317 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
318
319 scoped_refptr<SpdyStream> spdy_stream1;
320 TestOldCompletionCallback callback1;
321 EXPECT_EQ(OK, session->CreateStream(url,
322 MEDIUM,
323 &spdy_stream1,
324 BoundNetLog(),
325 &callback1));
326 scoped_ptr<TestSpdyStreamDelegate> delegate(
327 new TestSpdyStreamDelegate(&callback1));
328 spdy_stream1->SetDelegate(delegate.get());
329
330 // Enable sending of PING.
331 SpdySession::set_enable_ping_based_connection_checking(true);
332 SpdySession::set_connection_at_risk_of_loss_ms(0);
333 SpdySession::set_trailing_ping_delay_time_ms(0);
334 SpdySession::set_hung_interval_ms(0);
335
336 // Send a PING frame.
337 session->WritePingFrame(1);
338 EXPECT_LT(0, session->pings_in_flight());
339 EXPECT_GT(session->next_ping_id(), static_cast<uint32>(1));
340 EXPECT_TRUE(session->check_ping_status_pending());
341
342 // Assert session is not closed.
343 EXPECT_FALSE(session->IsClosed());
344 EXPECT_LT(0u, session->num_active_streams());
345 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
346
347 // We set last time we have received any data in 1 sec less than now.
348 // CheckPingStatus will trigger timeout because hung interval is zero.
349 base::TimeTicks now = base::TimeTicks::Now();
350 session->received_data_time_ = now - base::TimeDelta::FromSeconds(1);
351 session->CheckPingStatus(now);
352
353 EXPECT_TRUE(session->IsClosed());
354 EXPECT_EQ(0u, session->num_active_streams());
355 EXPECT_EQ(0u, session->num_unclaimed_pushed_streams());
356 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
357
358 // Delete the first session.
359 session = NULL;
360 }
361
264 class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > { 362 class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > {
265 public: 363 public:
266 StreamReleaserCallback(SpdySession* session, 364 StreamReleaserCallback(SpdySession* session,
267 SpdyStream* first_stream) 365 SpdyStream* first_stream)
268 : session_(session), first_stream_(first_stream) {} 366 : session_(session), first_stream_(first_stream) {}
269 ~StreamReleaserCallback() {} 367 ~StreamReleaserCallback() {}
270 368
271 int WaitForResult() { return callback_.WaitForResult(); } 369 int WaitForResult() { return callback_.WaitForResult(); }
272 370
273 virtual void RunWithParams(const Tuple1<int>& params) { 371 virtual void RunWithParams(const Tuple1<int>& params) {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 spdy::SpdySettings test_settings; 914 spdy::SpdySettings test_settings;
817 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); 915 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams));
818 916
819 test_settings_storage->Set(test_host_port_pair, test_settings); 917 test_settings_storage->Set(test_host_port_pair, test_settings);
820 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size()); 918 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size());
821 spdy_session_pool->OnIPAddressChanged(); 919 spdy_session_pool->OnIPAddressChanged();
822 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); 920 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size());
823 } 921 }
824 922
825 } // namespace net 923 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698