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

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

Issue 321513002: SpdySession go-away on network change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix IPAddressChanged. Created 6 years, 6 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_pool.cc ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_pool.h" 5 #include "net/spdy/spdy_session_pool.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 503
504 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { 504 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) {
505 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); 505 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS);
506 } 506 }
507 507
508 // Construct a Pool with SpdySessions in various availability states. Simulate 508 // Construct a Pool with SpdySessions in various availability states. Simulate
509 // an IP address change. Ensure sessions gracefully shut down. Regression test 509 // an IP address change. Ensure sessions gracefully shut down. Regression test
510 // for crbug.com/379469. 510 // for crbug.com/379469.
511 TEST_P(SpdySessionPoolTest, IPAddressChanged) { 511 TEST_P(SpdySessionPoolTest, IPAddressChanged) {
512 MockConnect connect_data(SYNCHRONOUS, OK); 512 MockConnect connect_data(SYNCHRONOUS, OK);
513 session_deps_.host_resolver->set_synchronous_mode(true);
514 SpdyTestUtil spdy_util(GetParam());
515
513 MockRead reads[] = { 516 MockRead reads[] = {
514 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. 517 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
515 }; 518 };
516 session_deps_.host_resolver->set_synchronous_mode(true); 519 scoped_ptr<SpdyFrame> req(
520 spdy_util.ConstructSpdyGet("http://www.a.com", false, 1, MEDIUM));
521 MockWrite writes[] = {CreateMockWrite(*req, 1)};
517 522
518 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 523 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
519 data.set_connect_data(connect_data); 524 data.set_connect_data(connect_data);
520 session_deps_.socket_factory->AddSocketDataProvider(&data); 525 session_deps_.socket_factory->AddSocketDataProvider(&data);
521 526
522 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 527 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
523 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 528 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
524 529
525 CreateNetworkSession(); 530 CreateNetworkSession();
526 531
527 // Set up session 1: Available, but idle. 532 // Set up session A: Going away, but with an active stream.
528 const std::string kTestHost1("http://www.a.com");
529 HostPortPair test_host_port_pair1(kTestHost1, 80);
530 SpdySessionKey key1(
531 test_host_port_pair1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
532 base::WeakPtr<SpdySession> session1 =
533 CreateInsecureSpdySession(http_session_, key1, BoundNetLog());
534 EXPECT_TRUE(session1->IsAvailable());
535
536 // Set up session 2: Going away, but with an active stream.
537 session_deps_.socket_factory->AddSocketDataProvider(&data); 533 session_deps_.socket_factory->AddSocketDataProvider(&data);
538 const std::string kTestHost2("http://www.b.com"); 534 const std::string kTestHostA("http://www.a.com");
539 HostPortPair test_host_port_pair2(kTestHost2, 80); 535 HostPortPair test_host_port_pairA(kTestHostA, 80);
540 SpdySessionKey key2( 536 SpdySessionKey keyA(
541 test_host_port_pair2, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 537 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
542 base::WeakPtr<SpdySession> session2 = 538 base::WeakPtr<SpdySession> sessionA =
543 CreateInsecureSpdySession(http_session_, key2, BoundNetLog()); 539 CreateInsecureSpdySession(http_session_, keyA, BoundNetLog());
544 GURL url2(kTestHost2); 540 GURL urlA(kTestHostA);
545 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously( 541 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously(
546 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, BoundNetLog()); 542 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, BoundNetLog());
547 test::StreamDelegateDoNothing delegate2(spdy_stream2); 543 test::StreamDelegateDoNothing delegateA(spdy_streamA);
548 spdy_stream2->SetDelegate(&delegate2); 544 spdy_streamA->SetDelegate(&delegateA);
549 545
550 scoped_ptr<SpdyHeaderBlock> headers( 546 scoped_ptr<SpdyHeaderBlock> headers(
551 SpdyTestUtil(GetParam()).ConstructGetHeaderBlock(url2.spec())); 547 spdy_util.ConstructGetHeaderBlock(urlA.spec()));
552 spdy_stream2->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); 548 spdy_streamA->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND);
553 EXPECT_TRUE(spdy_stream2->HasUrlFromHeaders()); 549 EXPECT_TRUE(spdy_streamA->HasUrlFromHeaders());
554 550
555 session2->MakeUnavailable(); 551 base::MessageLoop::current()->RunUntilIdle(); // Allow headers to write.
556 EXPECT_TRUE(session2->IsGoingAway()); 552 EXPECT_TRUE(delegateA.send_headers_completed());
557 553
558 // Set up session 3: Draining. 554 sessionA->MakeUnavailable();
555 EXPECT_TRUE(sessionA->IsGoingAway());
556 EXPECT_FALSE(delegateA.StreamIsClosed());
557
558 // Set up session B: Available, but idle.
559 const std::string kTestHostB("http://www.b.com");
560 HostPortPair test_host_port_pairB(kTestHostB, 80);
561 SpdySessionKey keyB(
562 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
563 base::WeakPtr<SpdySession> sessionB =
564 CreateInsecureSpdySession(http_session_, keyB, BoundNetLog());
565 EXPECT_TRUE(sessionB->IsAvailable());
566
567 // Set up session C: Draining.
559 session_deps_.socket_factory->AddSocketDataProvider(&data); 568 session_deps_.socket_factory->AddSocketDataProvider(&data);
560 const std::string kTestHost3("http://www.c.com"); 569 const std::string kTestHostC("http://www.c.com");
561 HostPortPair test_host_port_pair3(kTestHost3, 80); 570 HostPortPair test_host_port_pairC(kTestHostC, 80);
562 SpdySessionKey key3( 571 SpdySessionKey keyC(
563 test_host_port_pair3, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 572 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
564 base::WeakPtr<SpdySession> session3 = 573 base::WeakPtr<SpdySession> sessionC =
565 CreateInsecureSpdySession(http_session_, key3, BoundNetLog()); 574 CreateInsecureSpdySession(http_session_, keyC, BoundNetLog());
566 575
567 session3->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); 576 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!");
568 EXPECT_TRUE(session3->IsDraining()); 577 EXPECT_TRUE(sessionC->IsDraining());
569 578
570 spdy_session_pool_->OnIPAddressChanged(); 579 spdy_session_pool_->OnIPAddressChanged();
571 580
572 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) 581 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS)
573 // TODO(jgraettinger): This should be draining when crbug.com/324653 is fixed. 582 EXPECT_TRUE(sessionA->IsGoingAway());
574 EXPECT_TRUE(session1->IsGoingAway()); 583 EXPECT_TRUE(sessionB->IsDraining());
575 EXPECT_TRUE(session2->IsGoingAway()); 584 EXPECT_TRUE(sessionC->IsDraining());
576 EXPECT_TRUE(session3->IsDraining());
577 585
578 EXPECT_FALSE(delegate2.StreamIsClosed()); 586 EXPECT_EQ(1u, sessionA->num_active_streams()); // Stream is still active.
587 EXPECT_FALSE(delegateA.StreamIsClosed());
579 588
580 session1->CloseSessionOnError(ERR_ABORTED, "Closing"); 589 sessionA->CloseSessionOnError(ERR_ABORTED, "Closing");
581 session2->CloseSessionOnError(ERR_ABORTED, "Closing"); 590 sessionB->CloseSessionOnError(ERR_ABORTED, "Closing");
582 591
583 EXPECT_TRUE(delegate2.StreamIsClosed()); 592 EXPECT_TRUE(delegateA.StreamIsClosed());
584 EXPECT_EQ(ERR_ABORTED, delegate2.WaitForClose()); 593 EXPECT_EQ(ERR_ABORTED, delegateA.WaitForClose());
585 #else 594 #else
586 EXPECT_TRUE(session1->IsDraining()); 595 EXPECT_TRUE(sessionA->IsDraining());
587 EXPECT_TRUE(session2->IsDraining()); 596 EXPECT_TRUE(sessionB->IsDraining());
588 EXPECT_TRUE(session3->IsDraining()); 597 EXPECT_TRUE(sessionC->IsDraining());
589 598
590 EXPECT_TRUE(delegate2.StreamIsClosed()); 599 EXPECT_TRUE(delegateA.StreamIsClosed());
591 EXPECT_EQ(ERR_NETWORK_CHANGED, delegate2.WaitForClose()); 600 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateA.WaitForClose());
592 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) 601 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS)
593 } 602 }
594 603
595 } // namespace 604 } // namespace
596 605
597 } // namespace net 606 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698