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

Side by Side Diff: net/spdy/spdy_session_spdy3_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_spdy2_unittest.cc ('k') | net/spdy/spdy_stream.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) 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 SPDY3 framer. 284 // Give the session a SPDY3 framer.
285 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(3)); 285 session->buffered_spdy_framer_.reset(new BufferedSpdyFramer(3));
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)[":path"] = "/"; 291 (*request_headers)[":path"] = "/";
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[":scheme"] = "http"; 299 headers[":scheme"] = "http";
300 headers[":host"] = "www.google.com"; 300 headers[":host"] = "www.google.com";
301 headers[":path"] = "/a.dat"; 301 headers[":path"] = "/a.dat";
302 session->OnSynStream(2, 1, 0, 0, true, false, headers); 302 session->OnSynStream(2, 1, 0, 0, true, false, headers);
303 303
304 // Verify that there is one unclaimed push stream. 304 // Verify that there is one unclaimed push stream.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); 395 session->set_hung_interval(base::TimeDelta::FromSeconds(0));
396 396
397 // Send a PING frame. 397 // Send a PING frame.
398 session->WritePingFrame(1); 398 session->WritePingFrame(1);
399 EXPECT_LT(0, session->pings_in_flight()); 399 EXPECT_LT(0, session->pings_in_flight());
400 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); 400 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1));
401 EXPECT_TRUE(session->check_ping_status_pending()); 401 EXPECT_TRUE(session->check_ping_status_pending());
402 402
403 // Assert session is not closed. 403 // Assert session is not closed.
404 EXPECT_FALSE(session->IsClosed()); 404 EXPECT_FALSE(session->IsClosed());
405 EXPECT_LT(0u, session->num_active_streams()); 405 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams());
406 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); 406 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
407 407
408 // We set last time we have received any data in 1 sec less than now. 408 // We set last time we have received any data in 1 sec less than now.
409 // CheckPingStatus will trigger timeout because hung interval is zero. 409 // CheckPingStatus will trigger timeout because hung interval is zero.
410 base::TimeTicks now = base::TimeTicks::Now(); 410 base::TimeTicks now = base::TimeTicks::Now();
411 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); 411 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1);
412 session->CheckPingStatus(now); 412 session->CheckPingStatus(now);
413 413
414 EXPECT_TRUE(session->IsClosed()); 414 EXPECT_TRUE(session->IsClosed());
415 EXPECT_EQ(0u, session->num_active_streams()); 415 EXPECT_EQ(0u, session->num_active_streams());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 spdy_session_pool->CloseIdleSessions(); 515 spdy_session_pool->CloseIdleSessions();
516 EXPECT_TRUE(session1->is_active()); 516 EXPECT_TRUE(session1->is_active());
517 EXPECT_FALSE(session1->IsClosed()); 517 EXPECT_FALSE(session1->IsClosed());
518 EXPECT_TRUE(session2->is_active()); 518 EXPECT_TRUE(session2->is_active());
519 EXPECT_FALSE(session2->IsClosed()); 519 EXPECT_FALSE(session2->IsClosed());
520 EXPECT_TRUE(session3->is_active()); 520 EXPECT_TRUE(session3->is_active());
521 EXPECT_FALSE(session3->IsClosed()); 521 EXPECT_FALSE(session3->IsClosed());
522 522
523 // Make sessions 1 and 3 inactive, but keep them open. 523 // Make sessions 1 and 3 inactive, but keep them open.
524 // Session 2 still open and active 524 // Session 2 still open and active
525 session1->CloseStream(spdy_stream1->stream_id(), OK); 525 session1->CloseCreatedStream(spdy_stream1, OK);
526 session3->CloseStream(spdy_stream3->stream_id(), OK); 526 session3->CloseCreatedStream(spdy_stream3, OK);
527 EXPECT_FALSE(session1->is_active()); 527 EXPECT_FALSE(session1->is_active());
528 EXPECT_FALSE(session1->IsClosed()); 528 EXPECT_FALSE(session1->IsClosed());
529 EXPECT_TRUE(session2->is_active()); 529 EXPECT_TRUE(session2->is_active());
530 EXPECT_FALSE(session2->IsClosed()); 530 EXPECT_FALSE(session2->IsClosed());
531 EXPECT_FALSE(session3->is_active()); 531 EXPECT_FALSE(session3->is_active());
532 EXPECT_FALSE(session3->IsClosed()); 532 EXPECT_FALSE(session3->IsClosed());
533 533
534 // Should close session 1 and 3, 2 should be left open 534 // Should close session 1 and 3, 2 should be left open
535 spdy_session_pool->CloseIdleSessions(); 535 spdy_session_pool->CloseIdleSessions();
536 EXPECT_FALSE(session1->is_active()); 536 EXPECT_FALSE(session1->is_active());
537 EXPECT_TRUE(session1->IsClosed()); 537 EXPECT_TRUE(session1->IsClosed());
538 EXPECT_TRUE(session2->is_active()); 538 EXPECT_TRUE(session2->is_active());
539 EXPECT_FALSE(session2->IsClosed()); 539 EXPECT_FALSE(session2->IsClosed());
540 EXPECT_FALSE(session3->is_active()); 540 EXPECT_FALSE(session3->is_active());
541 EXPECT_TRUE(session3->IsClosed()); 541 EXPECT_TRUE(session3->IsClosed());
542 542
543 // Should not do anything 543 // Should not do anything
544 spdy_session_pool->CloseIdleSessions(); 544 spdy_session_pool->CloseIdleSessions();
545 EXPECT_TRUE(session2->is_active()); 545 EXPECT_TRUE(session2->is_active());
546 EXPECT_FALSE(session2->IsClosed()); 546 EXPECT_FALSE(session2->IsClosed());
547 547
548 // Make 2 not active 548 // Make 2 not active
549 session2->CloseStream(spdy_stream2->stream_id(), OK); 549 session2->CloseCreatedStream(spdy_stream2, OK);
550 EXPECT_FALSE(session2->is_active()); 550 EXPECT_FALSE(session2->is_active());
551 EXPECT_FALSE(session2->IsClosed()); 551 EXPECT_FALSE(session2->IsClosed());
552 552
553 // This should close session 2 553 // This should close session 2
554 spdy_session_pool->CloseIdleSessions(); 554 spdy_session_pool->CloseIdleSessions();
555 EXPECT_FALSE(session2->is_active()); 555 EXPECT_FALSE(session2->is_active());
556 EXPECT_TRUE(session2->IsClosed()); 556 EXPECT_TRUE(session2->IsClosed());
557 } 557 }
558 558
559 // Start with max concurrent streams set to 1. Request two streams. Receive a 559 // Start with max concurrent streams set to 1. Request two streams. Receive a
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 SettingsMap new_settings; 1258 SettingsMap new_settings;
1259 int32 window_size = 1; 1259 int32 window_size = 1;
1260 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = 1260 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] =
1261 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); 1261 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size);
1262 1262
1263 // Set up the socket so we read a SETTINGS frame that sets 1263 // Set up the socket so we read a SETTINGS frame that sets
1264 // INITIAL_WINDOW_SIZE. 1264 // INITIAL_WINDOW_SIZE.
1265 MockConnect connect_data(SYNCHRONOUS, OK); 1265 MockConnect connect_data(SYNCHRONOUS, OK);
1266 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); 1266 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings));
1267 MockRead reads[] = { 1267 MockRead reads[] = {
1268 CreateMockRead(*settings_frame), 1268 CreateMockRead(*settings_frame, 0),
1269 MockRead(SYNCHRONOUS, 0, 0) // EOF 1269 MockRead(ASYNC, 0, 1) // EOF
1270 }; 1270 };
1271 1271
1272 SpdySessionDependencies session_deps; 1272 SpdySessionDependencies session_deps;
1273
1273 session_deps.host_resolver->set_synchronous_mode(true); 1274 session_deps.host_resolver->set_synchronous_mode(true);
1274 1275
1275 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 1276 scoped_ptr<DeterministicSocketData> data(
1276 data.set_connect_data(connect_data); 1277 new DeterministicSocketData(reads, arraysize(reads), NULL, 0));
1277 session_deps.socket_factory->AddSocketDataProvider(&data); 1278 data->set_connect_data(connect_data);
1279 session_deps.deterministic_socket_factory->AddSocketDataProvider(data.get());
1278 1280
1279 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1281 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1280 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); 1282 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
1281 1283
1282 scoped_refptr<HttpNetworkSession> http_session( 1284 scoped_refptr<HttpNetworkSession> http_session(
1283 SpdySessionDependencies::SpdyCreateSession(&session_deps)); 1285 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
1284 1286
1285 const std::string kTestHost("www.foo.com"); 1287 const std::string kTestHost("www.foo.com");
1286 const int kTestPort = 80; 1288 const int kTestPort = 80;
1287 HostPortPair test_host_port_pair(kTestHost, kTestPort); 1289 HostPortPair test_host_port_pair(kTestHost, kTestPort);
1288 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); 1290 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
1289 1291
1290 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); 1292 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
1291 1293
1292 // Create a session. 1294 // Create a session.
1293 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 1295 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
(...skipping 19 matching lines...) Expand all
1313 TestCompletionCallback callback1; 1315 TestCompletionCallback callback1;
1314 GURL url("http://www.google.com"); 1316 GURL url("http://www.google.com");
1315 EXPECT_EQ(OK, 1317 EXPECT_EQ(OK,
1316 session->CreateStream(url, 1318 session->CreateStream(url,
1317 MEDIUM, /* priority, not important */ 1319 MEDIUM, /* priority, not important */
1318 &spdy_stream1, 1320 &spdy_stream1,
1319 BoundNetLog(), 1321 BoundNetLog(),
1320 callback1.callback())); 1322 callback1.callback()));
1321 EXPECT_NE(spdy_stream1->send_window_size(), window_size); 1323 EXPECT_NE(spdy_stream1->send_window_size(), window_size);
1322 1324
1325 data->RunFor(1); // Process the SETTINGS frame, but not the EOF
1323 MessageLoop::current()->RunAllPending(); 1326 MessageLoop::current()->RunAllPending();
1324 EXPECT_EQ(session->initial_send_window_size(), window_size); 1327 EXPECT_EQ(session->initial_send_window_size(), window_size);
1325 EXPECT_EQ(spdy_stream1->send_window_size(), window_size); 1328 EXPECT_EQ(spdy_stream1->send_window_size(), window_size);
1326 1329
1327 // Release the first one, this will allow the second to be created. 1330 // Release the first one, this will allow the second to be created.
1328 spdy_stream1->Cancel(); 1331 spdy_stream1->Cancel();
1329 spdy_stream1 = NULL; 1332 spdy_stream1 = NULL;
1330 1333
1331 scoped_refptr<SpdyStream> spdy_stream2; 1334 scoped_refptr<SpdyStream> spdy_stream2;
1332 EXPECT_EQ(OK, 1335 EXPECT_EQ(OK,
1333 session->CreateStream(url, 1336 session->CreateStream(url,
1334 MEDIUM, /* priority, not important */ 1337 MEDIUM, /* priority, not important */
1335 &spdy_stream2, 1338 &spdy_stream2,
1336 BoundNetLog(), 1339 BoundNetLog(),
1337 callback1.callback())); 1340 callback1.callback()));
1338 1341
1339 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); 1342 EXPECT_EQ(spdy_stream2->send_window_size(), window_size);
1340 spdy_stream2->Cancel(); 1343 spdy_stream2->Cancel();
1341 spdy_stream2 = NULL; 1344 spdy_stream2 = NULL;
1342 } 1345 }
1343 1346
1344 TEST_F(SpdySessionSpdy3Test, OutOfOrderSynStreams) { 1347 TEST_F(SpdySessionSpdy3Test, OutOfOrderSynStreams) {
1345 // Construct the request. 1348 // Construct the request.
1346 MockConnect connect_data(SYNCHRONOUS, OK); 1349 MockConnect connect_data(SYNCHRONOUS, OK);
1347 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 1350 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, HIGHEST));
1348 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); 1351 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST));
1349 MockWrite writes[] = { 1352 MockWrite writes[] = {
1350 CreateMockWrite(*req1, 2), 1353 CreateMockWrite(*req1, 2),
1351 CreateMockWrite(*req2, 1), 1354 CreateMockWrite(*req2, 1),
1352 }; 1355 };
1353 1356
1354 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3)); 1357 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3));
1355 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true)); 1358 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true));
1356 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5)); 1359 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5));
1357 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true)); 1360 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true));
1358 MockRead reads[] = { 1361 MockRead reads[] = {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 http_session->GetTransportSocketPool( 1405 http_session->GetTransportSocketPool(
1403 HttpNetworkSession::NORMAL_SOCKET_POOL), 1406 HttpNetworkSession::NORMAL_SOCKET_POOL),
1404 BoundNetLog())); 1407 BoundNetLog()));
1405 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); 1408 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1406 1409
1407 scoped_refptr<SpdyStream> spdy_stream1; 1410 scoped_refptr<SpdyStream> spdy_stream1;
1408 TestCompletionCallback callback1; 1411 TestCompletionCallback callback1;
1409 GURL url1("http://www.google.com"); 1412 GURL url1("http://www.google.com");
1410 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, 1413 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1,
1411 BoundNetLog(), callback1.callback())); 1414 BoundNetLog(), callback1.callback()));
1412 EXPECT_EQ(1u, spdy_stream1->stream_id()); 1415 EXPECT_EQ(0u, spdy_stream1->stream_id());
1413 1416
1414 scoped_refptr<SpdyStream> spdy_stream2; 1417 scoped_refptr<SpdyStream> spdy_stream2;
1415 TestCompletionCallback callback2; 1418 TestCompletionCallback callback2;
1416 GURL url2("http://www.google.com"); 1419 GURL url2("http://www.google.com");
1417 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, 1420 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2,
1418 BoundNetLog(), callback2.callback())); 1421 BoundNetLog(), callback2.callback()));
1419 EXPECT_EQ(3u, spdy_stream2->stream_id()); 1422 EXPECT_EQ(0u, spdy_stream2->stream_id());
1420 1423
1421 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); 1424 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1422 (*headers)[":method"] = "GET"; 1425 (*headers)[":method"] = "GET";
1423 (*headers)[":scheme"] = url1.scheme(); 1426 (*headers)[":scheme"] = url1.scheme();
1424 (*headers)[":host"] = url1.host(); 1427 (*headers)[":host"] = url1.host();
1425 (*headers)[":path"] = url1.path(); 1428 (*headers)[":path"] = url1.path();
1426 (*headers)[":version"] = "HTTP/1.1"; 1429 (*headers)[":version"] = "HTTP/1.1";
1427 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock); 1430 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1428 *headers2 = *headers; 1431 *headers2 = *headers;
1429 1432
1430 spdy_stream1->set_spdy_headers(headers.Pass()); 1433 spdy_stream1->set_spdy_headers(headers.Pass());
1431 EXPECT_TRUE(spdy_stream1->HasUrl()); 1434 EXPECT_TRUE(spdy_stream1->HasUrl());
1432 1435
1433 spdy_stream2->set_spdy_headers(headers2.Pass()); 1436 spdy_stream2->set_spdy_headers(headers2.Pass());
1434 EXPECT_TRUE(spdy_stream2->HasUrl()); 1437 EXPECT_TRUE(spdy_stream2->HasUrl());
1435 1438
1436 spdy_stream1->SendRequest(false); 1439 spdy_stream1->SendRequest(false);
1437 spdy_stream2->SendRequest(false); 1440 spdy_stream2->SendRequest(false);
1438 MessageLoop::current()->RunAllPending(); 1441 MessageLoop::current()->RunAllPending();
1439 1442
1440 EXPECT_EQ(1u, spdy_stream1->stream_id()); 1443 EXPECT_EQ(3u, spdy_stream1->stream_id());
1441 EXPECT_EQ(3u, spdy_stream2->stream_id()); 1444 EXPECT_EQ(1u, spdy_stream2->stream_id());
1442 1445
1443 spdy_stream1->Cancel(); 1446 spdy_stream1->Cancel();
1444 spdy_stream1 = NULL; 1447 spdy_stream1 = NULL;
1445 1448
1446 spdy_stream2->Cancel(); 1449 spdy_stream2->Cancel();
1447 spdy_stream2 = NULL; 1450 spdy_stream2 = NULL;
1448 } 1451 }
1449 1452
1450 } // namespace net 1453 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_spdy2_unittest.cc ('k') | net/spdy/spdy_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698