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

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

Issue 10815074: Instead of enqueueing SPDY frames, enqueue SPDY streams that are ready to produce data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove logging and cleanup Created 8 years, 5 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_session_spdy3_unittest.cc » ('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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "net/base/host_cache.h" 7 #include "net/base/host_cache.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_log_unittest.h" 9 #include "net/base/net_log_unittest.h"
10 #include "net/spdy/spdy_io_buffer.h" 10 #include "net/spdy/spdy_io_buffer.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // Give the session a SPDY2 framer. 284 // Give the session a SPDY2 framer.
285 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(2)); 285 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(2));
286 286
287 // Create the associated stream and add to active streams. 287 // Create the associated stream and add to active streams.
288 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock); 288 scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock);
289 (*request_headers)["scheme"] = "http"; 289 (*request_headers)["scheme"] = "http";
290 (*request_headers)["host"] = "www.google.com"; 290 (*request_headers)["host"] = "www.google.com";
291 (*request_headers)["url"] = "/"; 291 (*request_headers)["url"] = "/";
292 292
293 scoped_refptr<SpdyStream> stream( 293 scoped_refptr<SpdyStream> stream(
294 new SpdyStream(session, 1, false, session->net_log_)); 294 new SpdyStream(session, false, session->net_log_));
295 stream->set_spdy_headers(request_headers.Pass()); 295 stream->set_spdy_headers(request_headers.Pass());
296 session->ActivateStream(stream); 296 session->ActivateStream(stream);
297 297
298 SpdyHeaderBlock headers; 298 SpdyHeaderBlock headers;
299 headers["url"] = "http://www.google.com/a.dat"; 299 headers["url"] = "http://www.google.com/a.dat";
300 session->OnSynStream(2, 1, 0, 0, true, false, headers); 300 session->OnSynStream(2, 1, 0, 0, true, false, headers);
301 301
302 // Verify that there is one unclaimed push stream. 302 // Verify that there is one unclaimed push stream.
303 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); 303 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams());
304 SpdySession::PushedStreamMap::iterator iter = 304 SpdySession::PushedStreamMap::iterator iter =
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); 391 session->set_hung_interval(base::TimeDelta::FromSeconds(0));
392 392
393 // Send a PING frame. 393 // Send a PING frame.
394 session->WritePingFrame(1); 394 session->WritePingFrame(1);
395 EXPECT_LT(0, session->pings_in_flight()); 395 EXPECT_LT(0, session->pings_in_flight());
396 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); 396 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1));
397 EXPECT_TRUE(session->check_ping_status_pending()); 397 EXPECT_TRUE(session->check_ping_status_pending());
398 398
399 // Assert session is not closed. 399 // Assert session is not closed.
400 EXPECT_FALSE(session->IsClosed()); 400 EXPECT_FALSE(session->IsClosed());
401 EXPECT_LT(0u, session->num_active_streams()); 401 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams());
402 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); 402 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
403 403
404 // We set last time we have received any data in 1 sec less than now. 404 // We set last time we have received any data in 1 sec less than now.
405 // CheckPingStatus will trigger timeout because hung interval is zero. 405 // CheckPingStatus will trigger timeout because hung interval is zero.
406 base::TimeTicks now = base::TimeTicks::Now(); 406 base::TimeTicks now = base::TimeTicks::Now();
407 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); 407 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1);
408 session->CheckPingStatus(now); 408 session->CheckPingStatus(now);
409 409
410 EXPECT_TRUE(session->IsClosed()); 410 EXPECT_TRUE(session->IsClosed());
411 EXPECT_EQ(0u, session->num_active_streams()); 411 EXPECT_EQ(0u, session->num_active_streams());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 spdy_session_pool->CloseIdleSessions(); 511 spdy_session_pool->CloseIdleSessions();
512 EXPECT_TRUE(session1->is_active()); 512 EXPECT_TRUE(session1->is_active());
513 EXPECT_FALSE(session1->IsClosed()); 513 EXPECT_FALSE(session1->IsClosed());
514 EXPECT_TRUE(session2->is_active()); 514 EXPECT_TRUE(session2->is_active());
515 EXPECT_FALSE(session2->IsClosed()); 515 EXPECT_FALSE(session2->IsClosed());
516 EXPECT_TRUE(session3->is_active()); 516 EXPECT_TRUE(session3->is_active());
517 EXPECT_FALSE(session3->IsClosed()); 517 EXPECT_FALSE(session3->IsClosed());
518 518
519 // Make sessions 1 and 3 inactive, but keep them open. 519 // Make sessions 1 and 3 inactive, but keep them open.
520 // Session 2 still open and active 520 // Session 2 still open and active
521 session1->CloseStream(spdy_stream1->stream_id(), OK); 521 session1->CloseCreatedStream(spdy_stream1, OK);
522 session3->CloseStream(spdy_stream3->stream_id(), OK); 522 session3->CloseCreatedStream(spdy_stream3, OK);
523 EXPECT_FALSE(session1->is_active()); 523 EXPECT_FALSE(session1->is_active());
524 EXPECT_FALSE(session1->IsClosed()); 524 EXPECT_FALSE(session1->IsClosed());
525 EXPECT_TRUE(session2->is_active()); 525 EXPECT_TRUE(session2->is_active());
526 EXPECT_FALSE(session2->IsClosed()); 526 EXPECT_FALSE(session2->IsClosed());
527 EXPECT_FALSE(session3->is_active()); 527 EXPECT_FALSE(session3->is_active());
528 EXPECT_FALSE(session3->IsClosed()); 528 EXPECT_FALSE(session3->IsClosed());
529 529
530 // Should close session 1 and 3, 2 should be left open 530 // Should close session 1 and 3, 2 should be left open
531 spdy_session_pool->CloseIdleSessions(); 531 spdy_session_pool->CloseIdleSessions();
532 EXPECT_FALSE(session1->is_active()); 532 EXPECT_FALSE(session1->is_active());
533 EXPECT_TRUE(session1->IsClosed()); 533 EXPECT_TRUE(session1->IsClosed());
534 EXPECT_TRUE(session2->is_active()); 534 EXPECT_TRUE(session2->is_active());
535 EXPECT_FALSE(session2->IsClosed()); 535 EXPECT_FALSE(session2->IsClosed());
536 EXPECT_FALSE(session3->is_active()); 536 EXPECT_FALSE(session3->is_active());
537 EXPECT_TRUE(session3->IsClosed()); 537 EXPECT_TRUE(session3->IsClosed());
538 538
539 // Should not do anything 539 // Should not do anything
540 spdy_session_pool->CloseIdleSessions(); 540 spdy_session_pool->CloseIdleSessions();
541 EXPECT_TRUE(session2->is_active()); 541 EXPECT_TRUE(session2->is_active());
542 EXPECT_FALSE(session2->IsClosed()); 542 EXPECT_FALSE(session2->IsClosed());
543 543
544 // Make 2 not active 544 // Make 2 not active
545 session2->CloseStream(spdy_stream2->stream_id(), OK); 545 session2->CloseCreatedStream(spdy_stream2, OK);
546 EXPECT_FALSE(session2->is_active()); 546 EXPECT_FALSE(session2->is_active());
547 EXPECT_FALSE(session2->IsClosed()); 547 EXPECT_FALSE(session2->IsClosed());
548 548
549 // This should close session 2 549 // This should close session 2
550 spdy_session_pool->CloseIdleSessions(); 550 spdy_session_pool->CloseIdleSessions();
551 EXPECT_FALSE(session2->is_active()); 551 EXPECT_FALSE(session2->is_active());
552 EXPECT_TRUE(session2->IsClosed()); 552 EXPECT_TRUE(session2->IsClosed());
553 } 553 }
554 554
555 // Start with max concurrent streams set to 1. Request two streams. Receive a 555 // Start with max concurrent streams set to 1. Request two streams. Receive a
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1170
1171 CapturingNetLog::CapturedEntry entry = entries[pos]; 1171 CapturingNetLog::CapturedEntry entry = entries[pos];
1172 int error_code = 0; 1172 int error_code = 0;
1173 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); 1173 ASSERT_TRUE(entry.GetNetErrorCode(&error_code));
1174 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); 1174 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code);
1175 } 1175 }
1176 1176
1177 TEST_F(SpdySessionSpdy2Test, OutOfOrderSynStreams) { 1177 TEST_F(SpdySessionSpdy2Test, OutOfOrderSynStreams) {
1178 // Construct the request. 1178 // Construct the request.
1179 MockConnect connect_data(SYNCHRONOUS, OK); 1179 MockConnect connect_data(SYNCHRONOUS, OK);
1180 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 1180 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, HIGHEST));
1181 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); 1181 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST));
1182 MockWrite writes[] = { 1182 MockWrite writes[] = {
1183 CreateMockWrite(*req1, 2), 1183 CreateMockWrite(*req1, 2),
1184 CreateMockWrite(*req2, 1), 1184 CreateMockWrite(*req2, 1),
1185 }; 1185 };
1186 1186
1187 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); 1187 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1));
1188 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); 1188 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true));
1189 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); 1189 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3));
1190 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true)); 1190 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(3, true));
1191 MockRead reads[] = { 1191 MockRead reads[] = {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 http_session->GetTransportSocketPool( 1235 http_session->GetTransportSocketPool(
1236 HttpNetworkSession::NORMAL_SOCKET_POOL), 1236 HttpNetworkSession::NORMAL_SOCKET_POOL),
1237 BoundNetLog())); 1237 BoundNetLog()));
1238 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); 1238 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1239 1239
1240 scoped_refptr<SpdyStream> spdy_stream1; 1240 scoped_refptr<SpdyStream> spdy_stream1;
1241 TestCompletionCallback callback1; 1241 TestCompletionCallback callback1;
1242 GURL url1("http://www.google.com"); 1242 GURL url1("http://www.google.com");
1243 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, 1243 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1,
1244 BoundNetLog(), callback1.callback())); 1244 BoundNetLog(), callback1.callback()));
1245 EXPECT_EQ(1u, spdy_stream1->stream_id()); 1245 EXPECT_EQ(0u, spdy_stream1->stream_id());
1246 1246
1247 scoped_refptr<SpdyStream> spdy_stream2; 1247 scoped_refptr<SpdyStream> spdy_stream2;
1248 TestCompletionCallback callback2; 1248 TestCompletionCallback callback2;
1249 GURL url2("http://www.google.com"); 1249 GURL url2("http://www.google.com");
1250 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, 1250 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2,
1251 BoundNetLog(), callback2.callback())); 1251 BoundNetLog(), callback2.callback()));
1252 EXPECT_EQ(3u, spdy_stream2->stream_id()); 1252 EXPECT_EQ(0u, spdy_stream2->stream_id());
1253 1253
1254 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); 1254 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1255 (*headers)["method"] = "GET"; 1255 (*headers)["method"] = "GET";
1256 (*headers)["scheme"] = url1.scheme(); 1256 (*headers)["scheme"] = url1.scheme();
1257 (*headers)["host"] = url1.host(); 1257 (*headers)["host"] = url1.host();
1258 (*headers)["url"] = url1.path(); 1258 (*headers)["url"] = url1.path();
1259 (*headers)["version"] = "HTTP/1.1"; 1259 (*headers)["version"] = "HTTP/1.1";
1260 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock); 1260 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1261 *headers2 = *headers; 1261 *headers2 = *headers;
1262 1262
1263 spdy_stream1->set_spdy_headers(headers.Pass()); 1263 spdy_stream1->set_spdy_headers(headers.Pass());
1264 EXPECT_TRUE(spdy_stream1->HasUrl()); 1264 EXPECT_TRUE(spdy_stream1->HasUrl());
1265 1265
1266 spdy_stream2->set_spdy_headers(headers2.Pass()); 1266 spdy_stream2->set_spdy_headers(headers2.Pass());
1267 EXPECT_TRUE(spdy_stream2->HasUrl()); 1267 EXPECT_TRUE(spdy_stream2->HasUrl());
1268 1268
1269 spdy_stream1->SendRequest(false); 1269 spdy_stream1->SendRequest(false);
1270 spdy_stream2->SendRequest(false); 1270 spdy_stream2->SendRequest(false);
1271 MessageLoop::current()->RunAllPending(); 1271 MessageLoop::current()->RunAllPending();
1272 1272
1273 EXPECT_EQ(1u, spdy_stream1->stream_id()); 1273 EXPECT_EQ(3u, spdy_stream1->stream_id());
1274 EXPECT_EQ(3u, spdy_stream2->stream_id()); 1274 EXPECT_EQ(1u, spdy_stream2->stream_id());
1275 1275
1276 spdy_stream1->Cancel(); 1276 spdy_stream1->Cancel();
1277 spdy_stream1 = NULL; 1277 spdy_stream1 = NULL;
1278 1278
1279 spdy_stream2->Cancel(); 1279 spdy_stream2->Cancel();
1280 spdy_stream2 = NULL; 1280 spdy_stream2 = NULL;
1281 } 1281 }
1282 1282
1283 } // namespace net 1283 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698