OLD | NEW |
---|---|
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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 CloseStream(stream6->id()); | 508 CloseStream(stream6->id()); |
509 | 509 |
510 InSequence s; | 510 InSequence s; |
511 EXPECT_CALL(*stream2, OnCanWrite()); | 511 EXPECT_CALL(*stream2, OnCanWrite()); |
512 EXPECT_CALL(*stream4, OnCanWrite()); | 512 EXPECT_CALL(*stream4, OnCanWrite()); |
513 session_.OnCanWrite(); | 513 session_.OnCanWrite(); |
514 EXPECT_FALSE(session_.WillingAndAbleToWrite()); | 514 EXPECT_FALSE(session_.WillingAndAbleToWrite()); |
515 } | 515 } |
516 | 516 |
517 TEST_P(QuicSessionTest, OnCanWriteLimitsNumWritesIfFlowControlBlocked) { | 517 TEST_P(QuicSessionTest, OnCanWriteLimitsNumWritesIfFlowControlBlocked) { |
518 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 518 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
519 true); | |
519 if (version() < QUIC_VERSION_19) { | 520 if (version() < QUIC_VERSION_19) { |
520 return; | 521 return; |
521 } | 522 } |
522 | 523 |
523 // Ensure connection level flow control blockage. | 524 // Ensure connection level flow control blockage. |
524 QuicFlowControllerPeer::SetSendWindowOffset(session_.flow_controller(), 0); | 525 QuicFlowControllerPeer::SetSendWindowOffset(session_.flow_controller(), 0); |
525 EXPECT_TRUE(session_.flow_controller()->IsBlocked()); | 526 EXPECT_TRUE(session_.flow_controller()->IsBlocked()); |
526 | 527 |
527 // Mark the crypto and headers streams as write blocked, we expect them to be | 528 // Mark the crypto and headers streams as write blocked, we expect them to be |
528 // allowed to write later. | 529 // allowed to write later. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 new MockConnection(true, SupportedVersions(GetParam())); | 677 new MockConnection(true, SupportedVersions(GetParam())); |
677 | 678 |
678 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1; | 679 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1; |
679 TestSession session(connection, kSmallerFlowControlWindow); | 680 TestSession session(connection, kSmallerFlowControlWindow); |
680 | 681 |
681 EXPECT_EQ(kDefaultFlowControlSendWindow, | 682 EXPECT_EQ(kDefaultFlowControlSendWindow, |
682 session.max_flow_control_receive_window_bytes()); | 683 session.max_flow_control_receive_window_bytes()); |
683 } | 684 } |
684 | 685 |
685 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstOutOfOrder) { | 686 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstOutOfOrder) { |
686 FLAGS_enable_quic_stream_flow_control_2 = true; | 687 FLAGS_enable_quic_stream_flow_control_2 = true; |
ramant (doing other things)
2014/06/17 21:58:56
hi rjshade,
This CL would have conflicts with th
Robbie Shade
2014/06/17 22:06:18
Done.
| |
687 FLAGS_enable_quic_connection_flow_control = true; | 688 FLAGS_enable_quic_connection_flow_control_2 = true; |
688 if (version() < QUIC_VERSION_19) { | 689 if (version() < QUIC_VERSION_19) { |
689 return; | 690 return; |
690 } | 691 } |
691 | 692 |
692 // Test that when we receive an out of order stream RST we correctly adjust | 693 // Test that when we receive an out of order stream RST we correctly adjust |
693 // our connection level flow control receive window. | 694 // our connection level flow control receive window. |
694 // On close, the stream should mark as consumed all bytes between the highest | 695 // On close, the stream should mark as consumed all bytes between the highest |
695 // byte consumed so far and the final byte offset from the RST frame. | 696 // byte consumed so far and the final byte offset from the RST frame. |
696 TestStream* stream = session_.CreateOutgoingDataStream(); | 697 TestStream* stream = session_.CreateOutgoingDataStream(); |
697 | 698 |
698 const QuicStreamOffset kByteOffset = 1 + kInitialFlowControlWindowForTest / 2; | 699 const QuicStreamOffset kByteOffset = 1 + kInitialFlowControlWindowForTest / 2; |
699 // Expect no stream WINDOW_UPDATE frames, as stream read side closed. | 700 // Expect no stream WINDOW_UPDATE frames, as stream read side closed. |
700 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0); | 701 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0); |
701 // We do expect a connection level WINDOW_UPDATE when the stream is reset. | 702 // We do expect a connection level WINDOW_UPDATE when the stream is reset. |
702 EXPECT_CALL(*connection_, | 703 EXPECT_CALL(*connection_, |
703 SendWindowUpdate( | 704 SendWindowUpdate( |
704 0, kInitialFlowControlWindowForTest + kByteOffset)).Times(1); | 705 0, kInitialFlowControlWindowForTest + kByteOffset)).Times(1); |
705 | 706 |
706 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 707 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
707 kByteOffset); | 708 kByteOffset); |
708 session_.OnRstStream(rst_frame); | 709 session_.OnRstStream(rst_frame); |
709 session_.PostProcessAfterData(); | 710 session_.PostProcessAfterData(); |
710 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 711 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); |
711 } | 712 } |
712 | 713 |
713 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { | 714 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { |
714 FLAGS_enable_quic_stream_flow_control_2 = true; | 715 FLAGS_enable_quic_stream_flow_control_2 = true; |
715 FLAGS_enable_quic_connection_flow_control = true; | 716 FLAGS_enable_quic_connection_flow_control_2 = true; |
716 if (version() < QUIC_VERSION_19) { | 717 if (version() < QUIC_VERSION_19) { |
717 return; | 718 return; |
718 } | 719 } |
719 | 720 |
720 // Test the situation where we receive a FIN on a stream, and before we fully | 721 // Test the situation where we receive a FIN on a stream, and before we fully |
721 // consume all the data from the sequencer buffer we locally RST the stream. | 722 // consume all the data from the sequencer buffer we locally RST the stream. |
722 // The bytes between highest consumed byte, and the final byte offset that we | 723 // The bytes between highest consumed byte, and the final byte offset that we |
723 // determined when the FIN arrived, should be marked as consumed at the | 724 // determined when the FIN arrived, should be marked as consumed at the |
724 // connection level flow controller when the stream is reset. | 725 // connection level flow controller when the stream is reset. |
725 TestStream* stream = session_.CreateOutgoingDataStream(); | 726 TestStream* stream = session_.CreateOutgoingDataStream(); |
(...skipping 19 matching lines...) Expand all Loading... | |
745 // Reset stream locally. | 746 // Reset stream locally. |
746 stream->Reset(QUIC_STREAM_CANCELLED); | 747 stream->Reset(QUIC_STREAM_CANCELLED); |
747 | 748 |
748 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 749 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); |
749 } | 750 } |
750 | 751 |
751 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { | 752 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { |
752 // Test that when we RST the stream (and tear down stream state), and then | 753 // Test that when we RST the stream (and tear down stream state), and then |
753 // receive a FIN from the peer, we correctly adjust our connection level flow | 754 // receive a FIN from the peer, we correctly adjust our connection level flow |
754 // control receive window. | 755 // control receive window. |
755 FLAGS_enable_quic_connection_flow_control = true; | 756 FLAGS_enable_quic_connection_flow_control_2 = true; |
756 if (version() < QUIC_VERSION_19) { | 757 if (version() < QUIC_VERSION_19) { |
757 return; | 758 return; |
758 } | 759 } |
759 | 760 |
760 // Connection starts with some non-zero highest received byte offset, | 761 // Connection starts with some non-zero highest received byte offset, |
761 // due to other active streams. | 762 // due to other active streams. |
762 const uint64 kInitialConnectionBytesConsumed = 567; | 763 const uint64 kInitialConnectionBytesConsumed = 567; |
763 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 764 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
764 EXPECT_LT(kInitialConnectionBytesConsumed, | 765 EXPECT_LT(kInitialConnectionBytesConsumed, |
765 kInitialConnectionHighestReceivedOffset); | 766 kInitialConnectionHighestReceivedOffset); |
(...skipping 22 matching lines...) Expand all Loading... | |
788 session_.flow_controller()->bytes_consumed()); | 789 session_.flow_controller()->bytes_consumed()); |
789 EXPECT_EQ( | 790 EXPECT_EQ( |
790 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer, | 791 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer, |
791 session_.flow_controller()->highest_received_byte_offset()); | 792 session_.flow_controller()->highest_received_byte_offset()); |
792 } | 793 } |
793 | 794 |
794 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstAfterRst) { | 795 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstAfterRst) { |
795 // Test that when we RST the stream (and tear down stream state), and then | 796 // Test that when we RST the stream (and tear down stream state), and then |
796 // receive a RST from the peer, we correctly adjust our connection level flow | 797 // receive a RST from the peer, we correctly adjust our connection level flow |
797 // control receive window. | 798 // control receive window. |
798 FLAGS_enable_quic_connection_flow_control = true; | 799 FLAGS_enable_quic_connection_flow_control_2 = true; |
799 if (version() < QUIC_VERSION_19) { | 800 if (version() < QUIC_VERSION_19) { |
800 return; | 801 return; |
801 } | 802 } |
802 | 803 |
803 // Connection starts with some non-zero highest received byte offset, | 804 // Connection starts with some non-zero highest received byte offset, |
804 // due to other active streams. | 805 // due to other active streams. |
805 const uint64 kInitialConnectionBytesConsumed = 567; | 806 const uint64 kInitialConnectionBytesConsumed = 567; |
806 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 807 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
807 EXPECT_LT(kInitialConnectionBytesConsumed, | 808 EXPECT_LT(kInitialConnectionBytesConsumed, |
808 kInitialConnectionHighestReceivedOffset); | 809 kInitialConnectionHighestReceivedOffset); |
(...skipping 19 matching lines...) Expand all Loading... | |
828 session_.flow_controller()->highest_received_byte_offset()); | 829 session_.flow_controller()->highest_received_byte_offset()); |
829 } | 830 } |
830 | 831 |
831 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { | 832 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { |
832 // Test that if we receive a stream RST with a highest byte offset that | 833 // Test that if we receive a stream RST with a highest byte offset that |
833 // violates flow control, that we close the connection. | 834 // violates flow control, that we close the connection. |
834 if (version() < QUIC_VERSION_17) { | 835 if (version() < QUIC_VERSION_17) { |
835 return; | 836 return; |
836 } | 837 } |
837 FLAGS_enable_quic_stream_flow_control_2 = true; | 838 FLAGS_enable_quic_stream_flow_control_2 = true; |
838 FLAGS_enable_quic_connection_flow_control = true; | 839 FLAGS_enable_quic_connection_flow_control_2 = true; |
839 | 840 |
840 const uint64 kLargeOffset = kInitialFlowControlWindowForTest + 1; | 841 const uint64 kLargeOffset = kInitialFlowControlWindowForTest + 1; |
841 EXPECT_CALL(*connection_, | 842 EXPECT_CALL(*connection_, |
842 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) | 843 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) |
843 .Times(2); | 844 .Times(2); |
844 | 845 |
845 // Check that stream frame + FIN results in connection close. | 846 // Check that stream frame + FIN results in connection close. |
846 TestStream* stream = session_.CreateOutgoingDataStream(); | 847 TestStream* stream = session_.CreateOutgoingDataStream(); |
847 stream->Reset(QUIC_STREAM_CANCELLED); | 848 stream->Reset(QUIC_STREAM_CANCELLED); |
848 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); | 849 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); |
849 vector<QuicStreamFrame> frames; | 850 vector<QuicStreamFrame> frames; |
850 frames.push_back(frame); | 851 frames.push_back(frame); |
851 session_.OnStreamFrames(frames); | 852 session_.OnStreamFrames(frames); |
852 | 853 |
853 // Check that RST results in connection close. | 854 // Check that RST results in connection close. |
854 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 855 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
855 kLargeOffset); | 856 kLargeOffset); |
856 session_.OnRstStream(rst_frame); | 857 session_.OnRstStream(rst_frame); |
857 } | 858 } |
858 | 859 |
859 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { | 860 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { |
860 ValueRestore<bool> old_stream_flag( | 861 ValueRestore<bool> old_stream_flag( |
861 &FLAGS_enable_quic_stream_flow_control_2, true); | 862 &FLAGS_enable_quic_stream_flow_control_2, true); |
862 ValueRestore<bool> old_connection_flag( | 863 ValueRestore<bool> old_connection_flag( |
863 &FLAGS_enable_quic_connection_flow_control, true); | 864 &FLAGS_enable_quic_connection_flow_control_2, true); |
864 if (version() < QUIC_VERSION_19) { | 865 if (version() < QUIC_VERSION_19) { |
865 return; | 866 return; |
866 } | 867 } |
867 | 868 |
868 // Test that after successful version negotiation, flow control is disabled | 869 // Test that after successful version negotiation, flow control is disabled |
869 // appropriately at both the connection and stream level. | 870 // appropriately at both the connection and stream level. |
870 | 871 |
871 // Initially both stream and connection flow control are enabled. | 872 // Initially both stream and connection flow control are enabled. |
872 TestStream* stream = session_.CreateOutgoingDataStream(); | 873 TestStream* stream = session_.CreateOutgoingDataStream(); |
873 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); | 874 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); |
874 EXPECT_TRUE(session_.flow_controller()->IsEnabled()); | 875 EXPECT_TRUE(session_.flow_controller()->IsEnabled()); |
875 | 876 |
876 // Version 17 implies that stream flow control is enabled, but connection | 877 // Version 17 implies that stream flow control is enabled, but connection |
877 // level is disabled. | 878 // level is disabled. |
878 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_17); | 879 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_17); |
879 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 880 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
880 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); | 881 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); |
881 | 882 |
882 // Version 16 means all flow control is disabled. | 883 // Version 16 means all flow control is disabled. |
883 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); | 884 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); |
884 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 885 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
885 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); | 886 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); |
886 } | 887 } |
887 | 888 |
888 } // namespace | 889 } // namespace |
889 } // namespace test | 890 } // namespace test |
890 } // namespace net | 891 } // namespace net |
OLD | NEW |