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

Side by Side Diff: net/quic/quic_stream_factory_test.cc

Issue 2124753005: Implements migration of a QUIC connection to a different destination address if specified by the se… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@write-error
Patch Set: Comments addressed. Created 4 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
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/quic/quic_stream_factory.h" 5 #include "net/quic/quic_stream_factory.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 2630 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 ERR_QUIC_PROTOCOL_ERROR, 2641 ERR_QUIC_PROTOCOL_ERROR,
2642 stream->SendRequest(request_headers, &response, callback_.callback())); 2642 stream->SendRequest(request_headers, &response, callback_.callback()));
2643 2643
2644 // Migration fails, and session is marked as going away. 2644 // Migration fails, and session is marked as going away.
2645 EXPECT_FALSE(HasActiveSession(host_port_pair_)); 2645 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2646 2646
2647 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 2647 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2648 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 2648 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2649 } 2649 }
2650 2650
2651 TEST_P(QuicStreamFactoryTest, ServerMigration) {
2652 Initialize();
2653 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2654 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2655 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2656
2657 std::unique_ptr<QuicEncryptedPacket> request_packet(
2658 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true));
2659 MockWrite writes1[] = {MockWrite(SYNCHRONOUS, request_packet->data(),
2660 request_packet->length(), 1)};
2661 MockRead reads1[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
2662 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1,
2663 arraysize(writes1));
2664 socket_factory_.AddSocketDataProvider(&socket_data1);
2665
2666 // Create request and QuicHttpStream.
2667 QuicStreamRequest request(factory_.get());
2668 EXPECT_EQ(ERR_IO_PENDING,
2669 request.Request(host_port_pair_, privacy_mode_,
2670 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2671 callback_.callback()));
2672 EXPECT_EQ(OK, callback_.WaitForResult());
2673 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
2674 EXPECT_TRUE(stream.get());
2675
2676 // Cause QUIC stream to be created.
2677 HttpRequestInfo request_info;
2678 request_info.method = "GET";
2679 request_info.url = GURL("https://www.example.org/");
2680 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2681 net_log_, CompletionCallback()));
2682
2683 // Ensure that session is alive and active.
2684 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_);
2685 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2686 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2687
2688 // Send GET request on stream.
2689 HttpResponseInfo response;
2690 HttpRequestHeaders request_headers;
2691 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2692 callback_.callback()));
2693
2694 IPEndPoint ip;
2695 session->GetDefaultSocket()->GetPeerAddress(&ip);
2696 DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " "
2697 << ip.port();
2698
2699 // Set up second socket data provider that is used after
2700 // migration. The request is rewritten to this new socket, and the
2701 // response to the request is read on this new socket.
2702 std::unique_ptr<QuicEncryptedPacket> ping(
2703 client_maker_.MakePingPacket(2, /*include_version=*/true));
2704 std::unique_ptr<QuicEncryptedPacket> client_rst(
2705 client_maker_.MakeAckAndRstPacket(3, false, kClientDataStreamId1,
2706 QUIC_STREAM_CANCELLED, 1, 1, 1, true));
2707 MockWrite writes2[] = {
2708 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0),
2709 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 3)};
2710 std::unique_ptr<QuicEncryptedPacket> response_headers_packet(
2711 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false));
2712 MockRead reads2[] = {MockRead(ASYNC, response_headers_packet->data(),
2713 response_headers_packet->length(), 1),
2714 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)};
2715 SequencedSocketData socket_data2(reads2, arraysize(reads2), writes2,
2716 arraysize(writes2));
2717 socket_factory_.AddSocketDataProvider(&socket_data2);
2718
2719 const uint8_t kTestIpAddress[] = {1, 2, 3, 4};
2720 const uint16_t kTestPort = 123;
2721 factory_->MigrateSessionToNewPeerAddress(
2722 session, IPEndPoint(IPAddress(kTestIpAddress), kTestPort), net_log_,
2723 nullptr);
2724
2725 session->GetDefaultSocket()->GetPeerAddress(&ip);
2726 DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " "
2727 << ip.port();
2728
2729 // The session should be alive and active.
2730 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2731 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2732 EXPECT_EQ(1u, session->GetNumActiveStreams());
2733
2734 // Run the message loop so that data queued in the new socket is read by the
2735 // packet reader.
2736 base::RunLoop().RunUntilIdle();
2737
2738 // Verify that response headers on the migrated socket were delivered to the
2739 // stream.
2740 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
2741 EXPECT_EQ(200, response.headers->response_code());
2742
2743 stream.reset();
2744
2745 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
2746 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
2747 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2748 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2749 }
2750
2651 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { 2751 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) {
2652 Initialize(); 2752 Initialize();
2653 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 2753 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2654 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2754 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2655 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2755 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2656 2756
2657 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; 2757 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
2658 std::unique_ptr<QuicEncryptedPacket> rst(ConstructClientRstPacket()); 2758 std::unique_ptr<QuicEncryptedPacket> rst(ConstructClientRstPacket());
2659 vector<MockWrite> writes; 2759 vector<MockWrite> writes;
2660 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); 2760 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after
4670 EXPECT_NE(session1, session2); 4770 EXPECT_NE(session1, session2);
4671 4771
4672 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); 4772 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id());
4673 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); 4773 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id());
4674 4774
4675 EXPECT_TRUE(AllDataConsumed()); 4775 EXPECT_TRUE(AllDataConsumed());
4676 } 4776 }
4677 4777
4678 } // namespace test 4778 } // namespace test
4679 } // namespace net 4779 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698