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

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

Issue 1231343004: relnote: Change QuicConnectionVisitorInterface::OnStreamFrames to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Fix_flag_quic_delay_retransmission_alarm_97271704
Patch Set: Created 5 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
« no previous file with comments | « net/quic/quic_session.cc ('k') | net/quic/test_tools/quic_test_utils.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/quic/quic_session.h" 5 #include "net/quic/quic_session.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); 569 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
570 CryptoHandshakeMessage msg; 570 CryptoHandshakeMessage msg;
571 session_.GetCryptoStream()->OnHandshakeMessage(msg); 571 session_.GetCryptoStream()->OnHandshakeMessage(msg);
572 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3, 572 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3,
573 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); 573 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
574 } 574 }
575 575
576 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) { 576 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) {
577 // Send two bytes of payload. 577 // Send two bytes of payload.
578 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); 578 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT"));
579 vector<QuicStreamFrame> frames; 579 session_.OnStreamFrame(data1);
580 frames.push_back(data1);
581 session_.OnStreamFrames(frames);
582 EXPECT_EQ(1u, session_.GetNumOpenStreams()); 580 EXPECT_EQ(1u, session_.GetNumOpenStreams());
583 581
584 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _)); 582 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _));
585 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); 583 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0);
586 session_.OnRstStream(rst1); 584 session_.OnRstStream(rst1);
587 EXPECT_EQ(0u, session_.GetNumOpenStreams()); 585 EXPECT_EQ(0u, session_.GetNumOpenStreams());
588 // Connection should remain alive. 586 // Connection should remain alive.
589 EXPECT_TRUE(connection_->connected()); 587 EXPECT_TRUE(connection_->connected());
590 } 588 }
591 589
592 TEST_P(QuicSessionTestServer, MultipleRstStreamsCauseSingleConnectionClose) { 590 TEST_P(QuicSessionTestServer, MultipleRstStreamsCauseSingleConnectionClose) {
593 // If multiple invalid reset stream frames arrive in a single packet, this 591 // If multiple invalid reset stream frames arrive in a single packet, this
594 // should trigger a connection close. However there is no need to send 592 // should trigger a connection close. However there is no need to send
595 // multiple connection close frames. 593 // multiple connection close frames.
596 594
597 // Create valid stream. 595 // Create valid stream.
598 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); 596 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT"));
599 vector<QuicStreamFrame> frames; 597 session_.OnStreamFrame(data1);
600 frames.push_back(data1);
601 session_.OnStreamFrames(frames);
602 EXPECT_EQ(1u, session_.GetNumOpenStreams()); 598 EXPECT_EQ(1u, session_.GetNumOpenStreams());
603 599
604 // Process first invalid stream reset, resulting in the connection being 600 // Process first invalid stream reset, resulting in the connection being
605 // closed. 601 // closed.
606 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)) 602 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID))
607 .Times(1); 603 .Times(1);
608 const QuicStreamId kLargeInvalidStreamId = 99999999; 604 const QuicStreamId kLargeInvalidStreamId = 99999999;
609 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); 605 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0);
610 session_.OnRstStream(rst1); 606 session_.OnRstStream(rst1);
611 QuicConnectionPeer::CloseConnection(connection_); 607 QuicConnectionPeer::CloseConnection(connection_);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 // Test the situation where we receive a FIN on a stream, and before we fully 771 // Test the situation where we receive a FIN on a stream, and before we fully
776 // consume all the data from the sequencer buffer we locally RST the stream. 772 // consume all the data from the sequencer buffer we locally RST the stream.
777 // The bytes between highest consumed byte, and the final byte offset that we 773 // The bytes between highest consumed byte, and the final byte offset that we
778 // determined when the FIN arrived, should be marked as consumed at the 774 // determined when the FIN arrived, should be marked as consumed at the
779 // connection level flow controller when the stream is reset. 775 // connection level flow controller when the stream is reset.
780 TestStream* stream = session_.CreateOutgoingDynamicStream(); 776 TestStream* stream = session_.CreateOutgoingDynamicStream();
781 777
782 const QuicStreamOffset kByteOffset = 778 const QuicStreamOffset kByteOffset =
783 kInitialSessionFlowControlWindowForTest / 2; 779 kInitialSessionFlowControlWindowForTest / 2;
784 QuicStreamFrame frame(stream->id(), true, kByteOffset, StringPiece()); 780 QuicStreamFrame frame(stream->id(), true, kByteOffset, StringPiece());
785 vector<QuicStreamFrame> frames; 781 session_.OnStreamFrame(frame);
786 frames.push_back(frame);
787 session_.OnStreamFrames(frames);
788 session_.PostProcessAfterData(); 782 session_.PostProcessAfterData();
789 EXPECT_TRUE(connection_->connected()); 783 EXPECT_TRUE(connection_->connected());
790 784
791 EXPECT_EQ(0u, stream->flow_controller()->bytes_consumed()); 785 EXPECT_EQ(0u, stream->flow_controller()->bytes_consumed());
792 EXPECT_EQ(kByteOffset, 786 EXPECT_EQ(kByteOffset,
793 stream->flow_controller()->highest_received_byte_offset()); 787 stream->flow_controller()->highest_received_byte_offset());
794 788
795 // Reset stream locally. 789 // Reset stream locally.
796 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); 790 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
797 stream->Reset(QUIC_STREAM_CANCELLED); 791 stream->Reset(QUIC_STREAM_CANCELLED);
(...skipping 19 matching lines...) Expand all
817 TestStream* stream = session_.CreateOutgoingDynamicStream(); 811 TestStream* stream = session_.CreateOutgoingDynamicStream();
818 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); 812 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
819 stream->Reset(QUIC_STREAM_CANCELLED); 813 stream->Reset(QUIC_STREAM_CANCELLED);
820 814
821 // Now receive a response from the peer with a FIN. We should handle this by 815 // Now receive a response from the peer with a FIN. We should handle this by
822 // adjusting the connection level flow control receive window to take into 816 // adjusting the connection level flow control receive window to take into
823 // account the total number of bytes sent by the peer. 817 // account the total number of bytes sent by the peer.
824 const QuicStreamOffset kByteOffset = 5678; 818 const QuicStreamOffset kByteOffset = 5678;
825 string body = "hello"; 819 string body = "hello";
826 QuicStreamFrame frame(stream->id(), true, kByteOffset, StringPiece(body)); 820 QuicStreamFrame frame(stream->id(), true, kByteOffset, StringPiece(body));
827 vector<QuicStreamFrame> frames; 821 session_.OnStreamFrame(frame);
828 frames.push_back(frame);
829 session_.OnStreamFrames(frames);
830 822
831 QuicStreamOffset total_stream_bytes_sent_by_peer = 823 QuicStreamOffset total_stream_bytes_sent_by_peer =
832 kByteOffset + body.length(); 824 kByteOffset + body.length();
833 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer, 825 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer,
834 session_.flow_controller()->bytes_consumed()); 826 session_.flow_controller()->bytes_consumed());
835 EXPECT_EQ( 827 EXPECT_EQ(
836 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer, 828 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer,
837 session_.flow_controller()->highest_received_byte_offset()); 829 session_.flow_controller()->highest_received_byte_offset());
838 } 830 }
839 831
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; 893 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1;
902 EXPECT_CALL(*connection_, 894 EXPECT_CALL(*connection_,
903 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) 895 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA))
904 .Times(2); 896 .Times(2);
905 897
906 // Check that stream frame + FIN results in connection close. 898 // Check that stream frame + FIN results in connection close.
907 TestStream* stream = session_.CreateOutgoingDynamicStream(); 899 TestStream* stream = session_.CreateOutgoingDynamicStream();
908 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); 900 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
909 stream->Reset(QUIC_STREAM_CANCELLED); 901 stream->Reset(QUIC_STREAM_CANCELLED);
910 QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece()); 902 QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece());
911 vector<QuicStreamFrame> frames; 903 session_.OnStreamFrame(frame);
912 frames.push_back(frame);
913 session_.OnStreamFrames(frames);
914 904
915 // Check that RST results in connection close. 905 // Check that RST results in connection close.
916 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, 906 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
917 kLargeOffset); 907 kLargeOffset);
918 session_.OnRstStream(rst_frame); 908 session_.OnRstStream(rst_frame);
919 } 909 }
920 910
921 TEST_P(QuicSessionTestServer, WindowUpdateUnblocksHeadersStream) { 911 TEST_P(QuicSessionTestServer, WindowUpdateUnblocksHeadersStream) {
922 // Test that a flow control blocked headers stream gets unblocked on recipt of 912 // Test that a flow control blocked headers stream gets unblocked on recipt of
923 // a WINDOW_UPDATE frame. 913 // a WINDOW_UPDATE frame.
924 914
925 // Set the headers stream to be flow control blocked. 915 // Set the headers stream to be flow control blocked.
926 QuicHeadersStream* headers_stream = 916 QuicHeadersStream* headers_stream =
927 QuicSpdySessionPeer::GetHeadersStream(&session_); 917 QuicSpdySessionPeer::GetHeadersStream(&session_);
928 QuicFlowControllerPeer::SetSendWindowOffset(headers_stream->flow_controller(), 918 QuicFlowControllerPeer::SetSendWindowOffset(headers_stream->flow_controller(),
929 0); 919 0);
930 EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked()); 920 EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked());
931 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); 921 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
932 EXPECT_TRUE(session_.IsStreamFlowControlBlocked()); 922 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
933 923
934 // Unblock the headers stream by supplying a WINDOW_UPDATE. 924 // Unblock the headers stream by supplying a WINDOW_UPDATE.
935 QuicWindowUpdateFrame window_update_frame(headers_stream->id(), 925 QuicWindowUpdateFrame window_update_frame(headers_stream->id(),
936 2 * kMinimumFlowControlSendWindow); 926 2 * kMinimumFlowControlSendWindow);
937 vector<QuicWindowUpdateFrame> frames; 927 session_.OnWindowUpdateFrame(window_update_frame);
938 frames.push_back(window_update_frame);
939 session_.OnWindowUpdateFrames(frames);
940 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); 928 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
941 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); 929 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
942 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); 930 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
943 } 931 }
944 932
945 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseConnectionClose) { 933 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseConnectionClose) {
946 // If a buggy/malicious peer creates too many streams that are not ended with 934 // If a buggy/malicious peer creates too many streams that are not ended with
947 // a FIN or RST then we send a connection close. 935 // a FIN or RST then we send a connection close.
948 EXPECT_CALL(*connection_, 936 EXPECT_CALL(*connection_,
949 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)).Times(1); 937 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)).Times(1);
950 938
951 const QuicStreamId kMaxStreams = 5; 939 const QuicStreamId kMaxStreams = 5;
952 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); 940 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams);
953 941
954 // Create kMaxStreams + 1 data streams, and close them all without receiving a 942 // Create kMaxStreams + 1 data streams, and close them all without receiving a
955 // FIN or a RST_STREAM from the client. 943 // FIN or a RST_STREAM from the client.
956 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 944 const QuicStreamId kFirstStreamId = kClientDataStreamId1;
957 const QuicStreamId kFinalStreamId = 945 const QuicStreamId kFinalStreamId =
958 kClientDataStreamId1 + 2 * kMaxStreams + 1; 946 kClientDataStreamId1 + 2 * kMaxStreams + 1;
959 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 947 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) {
960 QuicStreamFrame data1(i, false, 0, StringPiece("HT")); 948 QuicStreamFrame data1(i, false, 0, StringPiece("HT"));
961 vector<QuicStreamFrame> frames; 949 session_.OnStreamFrame(data1);
962 frames.push_back(data1);
963 session_.OnStreamFrames(frames);
964 EXPECT_EQ(1u, session_.GetNumOpenStreams()); 950 EXPECT_EQ(1u, session_.GetNumOpenStreams());
965 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); 951 EXPECT_CALL(*connection_, SendRstStream(i, _, _));
966 session_.CloseStream(i); 952 session_.CloseStream(i);
967 } 953 }
968 954
969 // Called after any new data is received by the session, and triggers the call 955 // Called after any new data is received by the session, and triggers the call
970 // to close the connection. 956 // to close the connection.
971 session_.PostProcessAfterData(); 957 session_.PostProcessAfterData();
972 } 958 }
973 959
974 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) { 960 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) {
975 // Verify that a draining stream (which has received a FIN but not consumed 961 // Verify that a draining stream (which has received a FIN but not consumed
976 // it) does not count against the open quota (because it is closed from the 962 // it) does not count against the open quota (because it is closed from the
977 // protocol point of view). 963 // protocol point of view).
978 EXPECT_CALL(*connection_, 964 EXPECT_CALL(*connection_,
979 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)).Times(0); 965 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)).Times(0);
980 966
981 const QuicStreamId kMaxStreams = 5; 967 const QuicStreamId kMaxStreams = 5;
982 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); 968 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams);
983 969
984 // Create kMaxStreams + 1 data streams, and mark them draining. 970 // Create kMaxStreams + 1 data streams, and mark them draining.
985 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 971 const QuicStreamId kFirstStreamId = kClientDataStreamId1;
986 const QuicStreamId kFinalStreamId = 972 const QuicStreamId kFinalStreamId =
987 kClientDataStreamId1 + 2 * kMaxStreams + 1; 973 kClientDataStreamId1 + 2 * kMaxStreams + 1;
988 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 974 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) {
989 QuicStreamFrame data1(i, true, 0, StringPiece("HT")); 975 QuicStreamFrame data1(i, true, 0, StringPiece("HT"));
990 vector<QuicStreamFrame> frames; 976 session_.OnStreamFrame(data1);
991 frames.push_back(data1);
992 session_.OnStreamFrames(frames);
993 EXPECT_EQ(1u, session_.GetNumOpenStreams()); 977 EXPECT_EQ(1u, session_.GetNumOpenStreams());
994 session_.StreamDraining(i); 978 session_.StreamDraining(i);
995 EXPECT_EQ(0u, session_.GetNumOpenStreams()); 979 EXPECT_EQ(0u, session_.GetNumOpenStreams());
996 } 980 }
997 981
998 // Called after any new data is received by the session, and triggers the call 982 // Called after any new data is received by the session, and triggers the call
999 // to close the connection. 983 // to close the connection.
1000 session_.PostProcessAfterData(); 984 session_.PostProcessAfterData();
1001 } 985 }
1002 986
(...skipping 13 matching lines...) Expand all
1016 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4)); 1000 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4));
1017 ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr); 1001 ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr);
1018 ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr); 1002 ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr);
1019 // And 5 should be not implicitly created. 1003 // And 5 should be not implicitly created.
1020 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5)); 1004 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5));
1021 } 1005 }
1022 1006
1023 } // namespace 1007 } // namespace
1024 } // namespace test 1008 } // namespace test
1025 } // namespace net 1009 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_session.cc ('k') | net/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698