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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 EXPECT_CALL(*connection_, | 738 EXPECT_CALL(*connection_, |
739 SendWindowUpdate( | 739 SendWindowUpdate( |
740 0, kInitialFlowControlWindowForTest + kByteOffset)).Times(1); | 740 0, kInitialFlowControlWindowForTest + kByteOffset)).Times(1); |
741 | 741 |
742 // Reset stream locally. | 742 // Reset stream locally. |
743 stream->Reset(QUIC_STREAM_CANCELLED); | 743 stream->Reset(QUIC_STREAM_CANCELLED); |
744 | 744 |
745 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 745 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); |
746 } | 746 } |
747 | 747 |
| 748 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { |
| 749 // Test that when we RST the stream (and tear down stream state), and then |
| 750 // receive a FIN from the peer, we correctly adjust our connection level flow |
| 751 // control receive window. |
| 752 FLAGS_enable_quic_connection_flow_control = true; |
| 753 if (version() < QUIC_VERSION_19) { |
| 754 return; |
| 755 } |
| 756 |
| 757 // Connection starts with some non-zero highest received byte offset, |
| 758 // due to other active streams. |
| 759 const uint64 kInitialConnectionBytesConsumed = 567; |
| 760 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
| 761 EXPECT_LT(kInitialConnectionBytesConsumed, |
| 762 kInitialConnectionHighestReceivedOffset); |
| 763 session_.flow_controller()->UpdateHighestReceivedOffset( |
| 764 kInitialConnectionHighestReceivedOffset); |
| 765 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
| 766 |
| 767 // Reset our stream: this results in the stream being closed locally. |
| 768 TestStream* stream = session_.CreateOutgoingDataStream(); |
| 769 stream->Reset(QUIC_STREAM_CANCELLED); |
| 770 |
| 771 // Now receive a response from the peer with a FIN. We should handle this by |
| 772 // adjusting the connection level flow control receive window to take into |
| 773 // account the total number of bytes sent by the peer. |
| 774 const QuicStreamOffset kByteOffset = 5678; |
| 775 string body = "hello"; |
| 776 IOVector data = MakeIOVector(body); |
| 777 session_.OnStreamFrames( |
| 778 {QuicStreamFrame(stream->id(), true, kByteOffset, data)}); |
| 779 |
| 780 QuicStreamOffset total_stream_bytes_sent_by_peer = |
| 781 kByteOffset + body.length(); |
| 782 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer, |
| 783 session_.flow_controller()->bytes_consumed()); |
| 784 EXPECT_EQ( |
| 785 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer, |
| 786 session_.flow_controller()->highest_received_byte_offset()); |
| 787 } |
| 788 |
| 789 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstAfterRst) { |
| 790 // Test that when we RST the stream (and tear down stream state), and then |
| 791 // receive a RST from the peer, we correctly adjust our connection level flow |
| 792 // control receive window. |
| 793 FLAGS_enable_quic_connection_flow_control = true; |
| 794 if (version() < QUIC_VERSION_19) { |
| 795 return; |
| 796 } |
| 797 |
| 798 // Connection starts with some non-zero highest received byte offset, |
| 799 // due to other active streams. |
| 800 const uint64 kInitialConnectionBytesConsumed = 567; |
| 801 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
| 802 EXPECT_LT(kInitialConnectionBytesConsumed, |
| 803 kInitialConnectionHighestReceivedOffset); |
| 804 session_.flow_controller()->UpdateHighestReceivedOffset( |
| 805 kInitialConnectionHighestReceivedOffset); |
| 806 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
| 807 |
| 808 // Reset our stream: this results in the stream being closed locally. |
| 809 TestStream* stream = session_.CreateOutgoingDataStream(); |
| 810 stream->Reset(QUIC_STREAM_CANCELLED); |
| 811 |
| 812 // Now receive a RST from the peer. We should handle this by adjusting the |
| 813 // connection level flow control receive window to take into account the total |
| 814 // number of bytes sent by the peer. |
| 815 const QuicStreamOffset kByteOffset = 5678; |
| 816 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
| 817 kByteOffset); |
| 818 session_.OnRstStream(rst_frame); |
| 819 |
| 820 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, |
| 821 session_.flow_controller()->bytes_consumed()); |
| 822 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, |
| 823 session_.flow_controller()->highest_received_byte_offset()); |
| 824 } |
| 825 |
748 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { | 826 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { |
749 ValueRestore<bool> old_stream_flag( | 827 ValueRestore<bool> old_stream_flag( |
750 &FLAGS_enable_quic_stream_flow_control_2, true); | 828 &FLAGS_enable_quic_stream_flow_control_2, true); |
751 ValueRestore<bool> old_connection_flag( | 829 ValueRestore<bool> old_connection_flag( |
752 &FLAGS_enable_quic_connection_flow_control, true); | 830 &FLAGS_enable_quic_connection_flow_control, true); |
753 if (version() < QUIC_VERSION_19) { | 831 if (version() < QUIC_VERSION_19) { |
754 return; | 832 return; |
755 } | 833 } |
756 | 834 |
757 // Test that after successful version negotiation, flow control is disabled | 835 // Test that after successful version negotiation, flow control is disabled |
(...skipping 12 matching lines...) Expand all Loading... |
770 | 848 |
771 // Version 16 means all flow control is disabled. | 849 // Version 16 means all flow control is disabled. |
772 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); | 850 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); |
773 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 851 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
774 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); | 852 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); |
775 } | 853 } |
776 | 854 |
777 } // namespace | 855 } // namespace |
778 } // namespace test | 856 } // namespace test |
779 } // namespace net | 857 } // namespace net |
OLD | NEW |