QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/quic_stream.h" |
| 6 | |
| 7 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 9 | #include <utility> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
renjietang | 15afba3 | 2019-10-23 14:32:35 -0700 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/core/frames/quic_rst_stream_frame.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/quic_connection.h" |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/quic_constants.h" |
renjietang | 15afba3 | 2019-10-23 14:32:35 -0700 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/core/quic_error_codes.h" |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/quic_write_blocked_list.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 19 | #include "net/third_party/quiche/src/quic/platform/api/quic_expect_bug.h" |
| 20 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 21 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 22 | #include "net/third_party/quiche/src/quic/platform/api/quic_mem_slice_storage.h" |
| 23 | #include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 25 | #include "net/third_party/quiche/src/quic/platform/api/quic_test_mem_slice_vector.h" |
| 26 | #include "net/third_party/quiche/src/quic/test_tools/quic_config_peer.h" |
| 27 | #include "net/third_party/quiche/src/quic/test_tools/quic_connection_peer.h" |
| 28 | #include "net/third_party/quiche/src/quic/test_tools/quic_flow_controller_peer.h" |
| 29 | #include "net/third_party/quiche/src/quic/test_tools/quic_session_peer.h" |
| 30 | #include "net/third_party/quiche/src/quic/test_tools/quic_stream_peer.h" |
| 31 | #include "net/third_party/quiche/src/quic/test_tools/quic_stream_sequencer_peer.h" |
| 32 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 33 | #include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h" |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 34 | #include "net/third_party/quiche/src/common/platform/api/quiche_optional.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 35 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 36 | |
| 37 | using testing::_; |
| 38 | using testing::AnyNumber; |
| 39 | using testing::AtLeast; |
| 40 | using testing::InSequence; |
| 41 | using testing::Invoke; |
| 42 | using testing::InvokeWithoutArgs; |
| 43 | using testing::Return; |
| 44 | using testing::StrictMock; |
| 45 | |
| 46 | namespace quic { |
| 47 | namespace test { |
| 48 | namespace { |
| 49 | |
| 50 | const char kData1[] = "FooAndBar"; |
| 51 | const char kData2[] = "EepAndBaz"; |
| 52 | const size_t kDataLen = 9; |
| 53 | |
| 54 | class TestStream : public QuicStream { |
| 55 | public: |
| 56 | TestStream(QuicStreamId id, QuicSession* session, StreamType type) |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 57 | : QuicStream(id, session, /*is_static=*/false, type) { |
| 58 | sequencer()->set_level_triggered(true); |
| 59 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 60 | |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 61 | TestStream(PendingStream* pending, StreamType type, bool is_static) |
| 62 | : QuicStream(pending, type, is_static) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 63 | |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 64 | MOCK_METHOD0(OnDataAvailable, void()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 65 | |
| 66 | MOCK_METHOD0(OnCanWriteNewData, void()); |
| 67 | |
| 68 | using QuicStream::CanWriteNewData; |
| 69 | using QuicStream::CanWriteNewDataAfterData; |
| 70 | using QuicStream::CloseWriteSide; |
| 71 | using QuicStream::fin_buffered; |
| 72 | using QuicStream::OnClose; |
| 73 | using QuicStream::WriteMemSlices; |
| 74 | using QuicStream::WriteOrBufferData; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 75 | |
| 76 | private: |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 77 | std::string data_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 80 | class QuicStreamTest : public QuicTestWithParam<ParsedQuicVersion> { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 81 | public: |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 82 | QuicStreamTest() |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 83 | : zero_(QuicTime::Delta::Zero()), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 84 | supported_versions_(AllSupportedVersions()) {} |
| 85 | |
| 86 | void Initialize() { |
| 87 | ParsedQuicVersionVector version_vector; |
| 88 | version_vector.push_back(GetParam()); |
| 89 | connection_ = new StrictMock<MockQuicConnection>( |
| 90 | &helper_, &alarm_factory_, Perspective::IS_SERVER, version_vector); |
| 91 | connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 92 | session_ = std::make_unique<StrictMock<MockQuicSession>>(connection_); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 93 | session_->Initialize(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 94 | |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 95 | QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( |
| 96 | session_->config(), kMinimumFlowControlSendWindow); |
dschinazi | 18cdf13 | 2019-10-09 16:08:18 -0700 | [diff] [blame] | 97 | QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesUnidirectional( |
| 98 | session_->config(), kMinimumFlowControlSendWindow); |
| 99 | QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional( |
| 100 | session_->config(), kMinimumFlowControlSendWindow); |
| 101 | QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesOutgoingBidirectional( |
| 102 | session_->config(), kMinimumFlowControlSendWindow); |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 103 | QuicConfigPeer::SetReceivedMaxUnidirectionalStreams(session_->config(), 10); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 104 | session_->OnConfigNegotiated(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 105 | |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 106 | stream_ = new StrictMock<TestStream>(kTestStreamId, session_.get(), |
| 107 | BIDIRECTIONAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 108 | EXPECT_NE(nullptr, stream_); |
| 109 | // session_ now owns stream_. |
| 110 | session_->ActivateStream(QuicWrapUnique(stream_)); |
| 111 | // Ignore resetting when session_ is terminated. |
| 112 | EXPECT_CALL(*session_, SendRstStream(kTestStreamId, _, _)) |
| 113 | .Times(AnyNumber()); |
| 114 | write_blocked_list_ = |
| 115 | QuicSessionPeer::GetWriteBlockedStreams(session_.get()); |
| 116 | } |
| 117 | |
bnc | c7d9e0c | 2019-04-16 10:22:15 -0700 | [diff] [blame] | 118 | bool fin_sent() { return stream_->fin_sent(); } |
| 119 | bool rst_sent() { return stream_->rst_sent(); } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 120 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 121 | bool HasWriteBlockedStreams() { |
| 122 | return write_blocked_list_->HasWriteBlockedSpecialStream() || |
| 123 | write_blocked_list_->HasWriteBlockedDataStreams(); |
| 124 | } |
| 125 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 126 | QuicConsumedData CloseStreamOnWriteError( |
| 127 | QuicStreamId id, |
| 128 | size_t /*write_length*/, |
| 129 | QuicStreamOffset /*offset*/, |
| 130 | StreamSendingState /*state*/, |
| 131 | QuicByteCount /*bytes_written*/, |
| 132 | quiche::QuicheOptional<EncryptionLevel> /*level*/) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 133 | session_->CloseStream(id); |
| 134 | return QuicConsumedData(1, false); |
| 135 | } |
| 136 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 137 | bool ClearResetStreamFrame(const QuicFrame& frame) { |
| 138 | EXPECT_EQ(RST_STREAM_FRAME, frame.type); |
| 139 | DeleteFrame(&const_cast<QuicFrame&>(frame)); |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | bool ClearStopSendingFrame(const QuicFrame& frame) { |
| 144 | EXPECT_EQ(STOP_SENDING_FRAME, frame.type); |
| 145 | DeleteFrame(&const_cast<QuicFrame&>(frame)); |
| 146 | return true; |
| 147 | } |
| 148 | |
| 149 | protected: |
| 150 | MockQuicConnectionHelper helper_; |
| 151 | MockAlarmFactory alarm_factory_; |
| 152 | MockQuicConnection* connection_; |
| 153 | std::unique_ptr<MockQuicSession> session_; |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 154 | StrictMock<TestStream>* stream_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 155 | QuicWriteBlockedList* write_blocked_list_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 156 | QuicTime::Delta zero_; |
| 157 | ParsedQuicVersionVector supported_versions_; |
renjietang | 940a532 | 2019-08-02 16:17:51 -0700 | [diff] [blame] | 158 | QuicStreamId kTestStreamId = |
| 159 | GetNthClientInitiatedBidirectionalStreamId(GetParam().transport_version, |
| 160 | 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 161 | }; |
| 162 | |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 163 | INSTANTIATE_TEST_SUITE_P(QuicStreamTests, |
| 164 | QuicStreamTest, |
dschinazi | 142051a | 2019-09-18 18:17:29 -0700 | [diff] [blame] | 165 | ::testing::ValuesIn(AllSupportedVersions()), |
| 166 | ::testing::PrintToStringParamName()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 167 | |
renjietang | 3544899 | 2019-05-08 17:08:57 -0700 | [diff] [blame] | 168 | TEST_P(QuicStreamTest, PendingStreamStaticness) { |
| 169 | Initialize(); |
| 170 | |
| 171 | PendingStream pending(kTestStreamId + 2, session_.get()); |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 172 | TestStream stream(&pending, StreamType::BIDIRECTIONAL, false); |
renjietang | 3544899 | 2019-05-08 17:08:57 -0700 | [diff] [blame] | 173 | EXPECT_FALSE(stream.is_static()); |
| 174 | |
| 175 | PendingStream pending2(kTestStreamId + 3, session_.get()); |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 176 | TestStream stream2(&pending2, StreamType::BIDIRECTIONAL, true); |
renjietang | 3544899 | 2019-05-08 17:08:57 -0700 | [diff] [blame] | 177 | EXPECT_TRUE(stream2.is_static()); |
| 178 | } |
| 179 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 180 | TEST_P(QuicStreamTest, PendingStreamTooMuchData) { |
| 181 | Initialize(); |
| 182 | |
| 183 | PendingStream pending(kTestStreamId + 2, session_.get()); |
| 184 | // Receive a stream frame that violates flow control: the byte offset is |
| 185 | // higher than the receive window offset. |
| 186 | QuicStreamFrame frame(kTestStreamId + 2, false, |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 187 | kInitialSessionFlowControlWindowForTest + 1, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 188 | |
| 189 | // Stream should not accept the frame, and the connection should be closed. |
| 190 | EXPECT_CALL(*connection_, |
| 191 | CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); |
| 192 | pending.OnStreamFrame(frame); |
| 193 | } |
| 194 | |
| 195 | TEST_P(QuicStreamTest, PendingStreamTooMuchDataInRstStream) { |
| 196 | Initialize(); |
| 197 | |
| 198 | PendingStream pending(kTestStreamId + 2, session_.get()); |
| 199 | // Receive a rst stream frame that violates flow control: the byte offset is |
| 200 | // higher than the receive window offset. |
| 201 | QuicRstStreamFrame frame(kInvalidControlFrameId, kTestStreamId + 2, |
| 202 | QUIC_STREAM_CANCELLED, |
| 203 | kInitialSessionFlowControlWindowForTest + 1); |
| 204 | |
| 205 | // Pending stream should not accept the frame, and the connection should be |
| 206 | // closed. |
| 207 | EXPECT_CALL(*connection_, |
| 208 | CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); |
| 209 | pending.OnRstStreamFrame(frame); |
| 210 | } |
| 211 | |
| 212 | TEST_P(QuicStreamTest, PendingStreamRstStream) { |
| 213 | Initialize(); |
| 214 | |
| 215 | PendingStream pending(kTestStreamId + 2, session_.get()); |
| 216 | QuicStreamOffset final_byte_offset = 7; |
| 217 | QuicRstStreamFrame frame(kInvalidControlFrameId, kTestStreamId + 2, |
| 218 | QUIC_STREAM_CANCELLED, final_byte_offset); |
| 219 | |
| 220 | // Pending stream should accept the frame and not close the connection. |
| 221 | EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| 222 | pending.OnRstStreamFrame(frame); |
| 223 | } |
| 224 | |
| 225 | TEST_P(QuicStreamTest, FromPendingStream) { |
| 226 | Initialize(); |
| 227 | |
| 228 | PendingStream pending(kTestStreamId + 2, session_.get()); |
| 229 | |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 230 | QuicStreamFrame frame(kTestStreamId + 2, false, 2, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 231 | pending.OnStreamFrame(frame); |
| 232 | pending.OnStreamFrame(frame); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 233 | QuicStreamFrame frame2(kTestStreamId + 2, true, 3, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 234 | pending.OnStreamFrame(frame2); |
| 235 | |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 236 | TestStream stream(&pending, StreamType::READ_UNIDIRECTIONAL, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 237 | EXPECT_EQ(3, stream.num_frames_received()); |
| 238 | EXPECT_EQ(3u, stream.stream_bytes_read()); |
| 239 | EXPECT_EQ(1, stream.num_duplicate_frames_received()); |
| 240 | EXPECT_EQ(true, stream.fin_received()); |
| 241 | EXPECT_EQ(frame2.offset + 1, |
| 242 | stream.flow_controller()->highest_received_byte_offset()); |
| 243 | EXPECT_EQ(frame2.offset + 1, |
| 244 | session_->flow_controller()->highest_received_byte_offset()); |
| 245 | } |
| 246 | |
| 247 | TEST_P(QuicStreamTest, FromPendingStreamThenData) { |
| 248 | Initialize(); |
| 249 | |
| 250 | PendingStream pending(kTestStreamId + 2, session_.get()); |
| 251 | |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 252 | QuicStreamFrame frame(kTestStreamId + 2, false, 2, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 253 | pending.OnStreamFrame(frame); |
| 254 | |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 255 | auto stream = |
| 256 | new TestStream(&pending, StreamType::READ_UNIDIRECTIONAL, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 257 | session_->ActivateStream(QuicWrapUnique(stream)); |
| 258 | |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 259 | QuicStreamFrame frame2(kTestStreamId + 2, true, 3, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 260 | stream->OnStreamFrame(frame2); |
| 261 | |
| 262 | EXPECT_EQ(2, stream->num_frames_received()); |
| 263 | EXPECT_EQ(2u, stream->stream_bytes_read()); |
| 264 | EXPECT_EQ(true, stream->fin_received()); |
| 265 | EXPECT_EQ(frame2.offset + 1, |
| 266 | stream->flow_controller()->highest_received_byte_offset()); |
| 267 | EXPECT_EQ(frame2.offset + 1, |
| 268 | session_->flow_controller()->highest_received_byte_offset()); |
| 269 | } |
| 270 | |
| 271 | TEST_P(QuicStreamTest, WriteAllData) { |
| 272 | Initialize(); |
| 273 | |
| 274 | size_t length = |
| 275 | 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 276 | connection_->transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 277 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 278 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 279 | VARIABLE_LENGTH_INTEGER_LENGTH_0, |
| 280 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0u); |
| 281 | connection_->SetMaxPacketLength(length); |
| 282 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 283 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 284 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 285 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 286 | EXPECT_FALSE(HasWriteBlockedStreams()); |
| 287 | } |
| 288 | |
| 289 | TEST_P(QuicStreamTest, NoBlockingIfNoDataOrFin) { |
| 290 | Initialize(); |
| 291 | |
| 292 | // Write no data and no fin. If we consume nothing we should not be write |
| 293 | // blocked. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 294 | EXPECT_QUIC_BUG( |
| 295 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(), false, nullptr), |
| 296 | ""); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 297 | EXPECT_FALSE(HasWriteBlockedStreams()); |
| 298 | } |
| 299 | |
| 300 | TEST_P(QuicStreamTest, BlockIfOnlySomeDataConsumed) { |
| 301 | Initialize(); |
| 302 | |
| 303 | // Write some data and no fin. If we consume some but not all of the data, |
| 304 | // we should be write blocked a not all the data was consumed. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 305 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 306 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 307 | return session_->ConsumeData(stream_->id(), 1u, 0u, NO_FIN, false, |
| 308 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 309 | })); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 310 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), false, |
| 311 | nullptr); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 312 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 313 | ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
| 314 | EXPECT_EQ(1u, stream_->BufferedDataBytes()); |
| 315 | } |
| 316 | |
| 317 | TEST_P(QuicStreamTest, BlockIfFinNotConsumedWithData) { |
| 318 | Initialize(); |
| 319 | |
| 320 | // Write some data and no fin. If we consume all the data but not the fin, |
| 321 | // we should be write blocked because the fin was not consumed. |
| 322 | // (This should never actually happen as the fin should be sent out with the |
| 323 | // last data) |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 324 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 325 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 326 | return session_->ConsumeData(stream_->id(), 2u, 0u, NO_FIN, false, |
| 327 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 328 | })); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 329 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true, |
| 330 | nullptr); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 331 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 332 | ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
| 333 | } |
| 334 | |
| 335 | TEST_P(QuicStreamTest, BlockIfSoloFinNotConsumed) { |
| 336 | Initialize(); |
| 337 | |
| 338 | // Write no data and a fin. If we consume nothing we should be write blocked, |
| 339 | // as the fin was not consumed. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 340 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 341 | .WillOnce(Return(QuicConsumedData(0, false))); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 342 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(), true, nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 343 | ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
| 344 | } |
| 345 | |
| 346 | TEST_P(QuicStreamTest, CloseOnPartialWrite) { |
| 347 | Initialize(); |
| 348 | |
| 349 | // Write some data and no fin. However, while writing the data |
| 350 | // close the stream and verify that MarkConnectionLevelWriteBlocked does not |
| 351 | // crash with an unknown stream. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 352 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 353 | .WillOnce(Invoke(this, &QuicStreamTest::CloseStreamOnWriteError)); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 354 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), false, |
| 355 | nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 356 | ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams()); |
| 357 | } |
| 358 | |
| 359 | TEST_P(QuicStreamTest, WriteOrBufferData) { |
| 360 | Initialize(); |
| 361 | |
| 362 | EXPECT_FALSE(HasWriteBlockedStreams()); |
| 363 | size_t length = |
| 364 | 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 365 | connection_->transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 366 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 367 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 368 | VARIABLE_LENGTH_INTEGER_LENGTH_0, |
| 369 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0u); |
| 370 | connection_->SetMaxPacketLength(length); |
| 371 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 372 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 373 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 374 | return session_->ConsumeData(stream_->id(), kDataLen - 1, 0u, NO_FIN, |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 375 | false, QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 376 | })); |
| 377 | stream_->WriteOrBufferData(kData1, false, nullptr); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 378 | |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 379 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 380 | EXPECT_EQ(1u, stream_->BufferedDataBytes()); |
| 381 | EXPECT_TRUE(HasWriteBlockedStreams()); |
| 382 | |
| 383 | // Queue a bytes_consumed write. |
| 384 | stream_->WriteOrBufferData(kData2, false, nullptr); |
| 385 | EXPECT_EQ(10u, stream_->BufferedDataBytes()); |
| 386 | // Make sure we get the tail of the first write followed by the bytes_consumed |
| 387 | InSequence s; |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 388 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 389 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 390 | return session_->ConsumeData(stream_->id(), kDataLen - 1, kDataLen - 1, |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 391 | NO_FIN, false, QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 392 | })); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 393 | EXPECT_CALL(*stream_, OnCanWriteNewData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 394 | stream_->OnCanWrite(); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 395 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 396 | |
| 397 | // And finally the end of the bytes_consumed. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 398 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 399 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 400 | return session_->ConsumeData(stream_->id(), 2u, 2 * kDataLen - 2, |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 401 | NO_FIN, false, QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 402 | })); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 403 | EXPECT_CALL(*stream_, OnCanWriteNewData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 404 | stream_->OnCanWrite(); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 405 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | TEST_P(QuicStreamTest, WriteOrBufferDataReachStreamLimit) { |
| 409 | Initialize(); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 410 | std::string data("aaaaa"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 411 | QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - data.length(), |
| 412 | stream_); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 413 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 414 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 415 | stream_->WriteOrBufferData(data, false, nullptr); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 416 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 417 | EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _)); |
| 418 | EXPECT_QUIC_BUG(stream_->WriteOrBufferData("a", false, nullptr), |
| 419 | "Write too many data via stream"); |
| 420 | } |
| 421 | |
| 422 | TEST_P(QuicStreamTest, ConnectionCloseAfterStreamClose) { |
| 423 | Initialize(); |
| 424 | |
| 425 | QuicStreamPeer::CloseReadSide(stream_); |
| 426 | stream_->CloseWriteSide(); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 427 | EXPECT_THAT(stream_->stream_error(), IsQuicStreamNoError()); |
| 428 | EXPECT_THAT(stream_->connection_error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 429 | stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, |
| 430 | ConnectionCloseSource::FROM_SELF); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 431 | EXPECT_THAT(stream_->stream_error(), IsQuicStreamNoError()); |
| 432 | EXPECT_THAT(stream_->connection_error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | TEST_P(QuicStreamTest, RstAlwaysSentIfNoFinSent) { |
| 436 | // For flow control accounting, a stream must send either a FIN or a RST frame |
| 437 | // before termination. |
| 438 | // Test that if no FIN has been sent, we send a RST. |
| 439 | |
| 440 | Initialize(); |
| 441 | EXPECT_FALSE(fin_sent()); |
| 442 | EXPECT_FALSE(rst_sent()); |
| 443 | |
| 444 | // Write some data, with no FIN. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 445 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 446 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 447 | return session_->ConsumeData(stream_->id(), 1u, 0u, NO_FIN, false, |
| 448 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 449 | })); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 450 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 1), false, |
| 451 | nullptr); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 452 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 453 | EXPECT_FALSE(fin_sent()); |
| 454 | EXPECT_FALSE(rst_sent()); |
| 455 | |
| 456 | // Now close the stream, and expect that we send a RST. |
| 457 | EXPECT_CALL(*session_, SendRstStream(_, _, _)); |
| 458 | stream_->OnClose(); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 459 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 460 | EXPECT_FALSE(fin_sent()); |
| 461 | EXPECT_TRUE(rst_sent()); |
| 462 | } |
| 463 | |
| 464 | TEST_P(QuicStreamTest, RstNotSentIfFinSent) { |
| 465 | // For flow control accounting, a stream must send either a FIN or a RST frame |
| 466 | // before termination. |
| 467 | // Test that if a FIN has been sent, we don't also send a RST. |
| 468 | |
| 469 | Initialize(); |
| 470 | EXPECT_FALSE(fin_sent()); |
| 471 | EXPECT_FALSE(rst_sent()); |
| 472 | |
| 473 | // Write some data, with FIN. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 474 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 475 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 476 | return session_->ConsumeData(stream_->id(), 1u, 0u, FIN, false, |
| 477 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 478 | })); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 479 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 1), true, |
| 480 | nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 481 | EXPECT_TRUE(fin_sent()); |
| 482 | EXPECT_FALSE(rst_sent()); |
| 483 | |
| 484 | // Now close the stream, and expect that we do not send a RST. |
| 485 | stream_->OnClose(); |
| 486 | EXPECT_TRUE(fin_sent()); |
| 487 | EXPECT_FALSE(rst_sent()); |
| 488 | } |
| 489 | |
| 490 | TEST_P(QuicStreamTest, OnlySendOneRst) { |
| 491 | // For flow control accounting, a stream must send either a FIN or a RST frame |
| 492 | // before termination. |
| 493 | // Test that if a stream sends a RST, it doesn't send an additional RST during |
| 494 | // OnClose() (this shouldn't be harmful, but we shouldn't do it anyway...) |
| 495 | |
| 496 | Initialize(); |
| 497 | EXPECT_FALSE(fin_sent()); |
| 498 | EXPECT_FALSE(rst_sent()); |
| 499 | |
| 500 | // Reset the stream. |
| 501 | const int expected_resets = 1; |
| 502 | EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(expected_resets); |
| 503 | stream_->Reset(QUIC_STREAM_CANCELLED); |
| 504 | EXPECT_FALSE(fin_sent()); |
| 505 | EXPECT_TRUE(rst_sent()); |
| 506 | |
| 507 | // Now close the stream (any further resets being sent would break the |
| 508 | // expectation above). |
| 509 | stream_->OnClose(); |
| 510 | EXPECT_FALSE(fin_sent()); |
| 511 | EXPECT_TRUE(rst_sent()); |
| 512 | } |
| 513 | |
| 514 | TEST_P(QuicStreamTest, StreamFlowControlMultipleWindowUpdates) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 515 | Initialize(); |
| 516 | |
| 517 | // If we receive multiple WINDOW_UPDATES (potentially out of order), then we |
| 518 | // want to make sure we latch the largest offset we see. |
| 519 | |
| 520 | // Initially should be default. |
| 521 | EXPECT_EQ( |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 522 | kMinimumFlowControlSendWindow, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 523 | QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller())); |
| 524 | |
| 525 | // Check a single WINDOW_UPDATE results in correct offset. |
| 526 | QuicWindowUpdateFrame window_update_1(kInvalidControlFrameId, stream_->id(), |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 527 | kMinimumFlowControlSendWindow + 5); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 528 | stream_->OnWindowUpdateFrame(window_update_1); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 529 | EXPECT_EQ(window_update_1.max_data, QuicFlowControllerPeer::SendWindowOffset( |
| 530 | stream_->flow_controller())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 531 | |
| 532 | // Now send a few more WINDOW_UPDATES and make sure that only the largest is |
| 533 | // remembered. |
| 534 | QuicWindowUpdateFrame window_update_2(kInvalidControlFrameId, stream_->id(), |
| 535 | 1); |
| 536 | QuicWindowUpdateFrame window_update_3(kInvalidControlFrameId, stream_->id(), |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 537 | kMinimumFlowControlSendWindow + 10); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 538 | QuicWindowUpdateFrame window_update_4(kInvalidControlFrameId, stream_->id(), |
| 539 | 5678); |
| 540 | stream_->OnWindowUpdateFrame(window_update_2); |
| 541 | stream_->OnWindowUpdateFrame(window_update_3); |
| 542 | stream_->OnWindowUpdateFrame(window_update_4); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 543 | EXPECT_EQ(window_update_3.max_data, QuicFlowControllerPeer::SendWindowOffset( |
| 544 | stream_->flow_controller())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | TEST_P(QuicStreamTest, FrameStats) { |
| 548 | Initialize(); |
| 549 | |
| 550 | EXPECT_EQ(0, stream_->num_frames_received()); |
| 551 | EXPECT_EQ(0, stream_->num_duplicate_frames_received()); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 552 | QuicStreamFrame frame(stream_->id(), false, 0, "."); |
| 553 | EXPECT_CALL(*stream_, OnDataAvailable()).Times(2); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 554 | stream_->OnStreamFrame(frame); |
| 555 | EXPECT_EQ(1, stream_->num_frames_received()); |
| 556 | EXPECT_EQ(0, stream_->num_duplicate_frames_received()); |
| 557 | stream_->OnStreamFrame(frame); |
| 558 | EXPECT_EQ(2, stream_->num_frames_received()); |
| 559 | EXPECT_EQ(1, stream_->num_duplicate_frames_received()); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 560 | QuicStreamFrame frame2(stream_->id(), false, 1, "abc"); |
| 561 | stream_->OnStreamFrame(frame2); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | // Verify that when we receive a packet which violates flow control (i.e. sends |
| 565 | // too much data on the stream) that the stream sequencer never sees this frame, |
| 566 | // as we check for violation and close the connection early. |
| 567 | TEST_P(QuicStreamTest, StreamSequencerNeverSeesPacketsViolatingFlowControl) { |
| 568 | Initialize(); |
| 569 | |
| 570 | // Receive a stream frame that violates flow control: the byte offset is |
| 571 | // higher than the receive window offset. |
| 572 | QuicStreamFrame frame(stream_->id(), false, |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 573 | kInitialSessionFlowControlWindowForTest + 1, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 574 | EXPECT_GT(frame.offset, QuicFlowControllerPeer::ReceiveWindowOffset( |
| 575 | stream_->flow_controller())); |
| 576 | |
| 577 | // Stream should not accept the frame, and the connection should be closed. |
| 578 | EXPECT_CALL(*connection_, |
| 579 | CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); |
| 580 | stream_->OnStreamFrame(frame); |
| 581 | } |
| 582 | |
| 583 | // Verify that after the consumer calls StopReading(), the stream still sends |
| 584 | // flow control updates. |
| 585 | TEST_P(QuicStreamTest, StopReadingSendsFlowControl) { |
| 586 | Initialize(); |
| 587 | |
| 588 | stream_->StopReading(); |
| 589 | |
| 590 | // Connection should not get terminated due to flow control errors. |
| 591 | EXPECT_CALL(*connection_, |
| 592 | CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)) |
| 593 | .Times(0); |
| 594 | EXPECT_CALL(*connection_, SendControlFrame(_)) |
| 595 | .Times(AtLeast(1)) |
bnc | 5b3c3be | 2019-06-25 10:37:09 -0700 | [diff] [blame] | 596 | .WillRepeatedly(Invoke(&ClearControlFrame)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 597 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 598 | std::string data(1000, 'x'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 599 | for (QuicStreamOffset offset = 0; |
| 600 | offset < 2 * kInitialStreamFlowControlWindowForTest; |
| 601 | offset += data.length()) { |
| 602 | QuicStreamFrame frame(stream_->id(), false, offset, data); |
| 603 | stream_->OnStreamFrame(frame); |
| 604 | } |
| 605 | EXPECT_LT( |
| 606 | kInitialStreamFlowControlWindowForTest, |
| 607 | QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller())); |
| 608 | } |
| 609 | |
| 610 | TEST_P(QuicStreamTest, FinalByteOffsetFromFin) { |
| 611 | Initialize(); |
| 612 | |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 613 | EXPECT_FALSE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 614 | |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 615 | QuicStreamFrame stream_frame_no_fin(stream_->id(), false, 1234, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 616 | stream_->OnStreamFrame(stream_frame_no_fin); |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 617 | EXPECT_FALSE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 618 | |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 619 | QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 620 | stream_->OnStreamFrame(stream_frame_with_fin); |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 621 | EXPECT_TRUE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | TEST_P(QuicStreamTest, FinalByteOffsetFromRst) { |
| 625 | Initialize(); |
| 626 | |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 627 | EXPECT_FALSE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 628 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(), |
| 629 | QUIC_STREAM_CANCELLED, 1234); |
| 630 | stream_->OnStreamReset(rst_frame); |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 631 | EXPECT_TRUE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | TEST_P(QuicStreamTest, InvalidFinalByteOffsetFromRst) { |
| 635 | Initialize(); |
| 636 | |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 637 | EXPECT_FALSE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 638 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(), |
| 639 | QUIC_STREAM_CANCELLED, 0xFFFFFFFFFFFF); |
| 640 | // Stream should not accept the frame, and the connection should be closed. |
| 641 | EXPECT_CALL(*connection_, |
| 642 | CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); |
| 643 | stream_->OnStreamReset(rst_frame); |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 644 | EXPECT_TRUE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 645 | stream_->OnClose(); |
| 646 | } |
| 647 | |
| 648 | TEST_P(QuicStreamTest, FinalByteOffsetFromZeroLengthStreamFrame) { |
| 649 | // When receiving Trailers, an empty stream frame is created with the FIN set, |
| 650 | // and is passed to OnStreamFrame. The Trailers may be sent in advance of |
| 651 | // queued body bytes being sent, and thus the final byte offset may exceed |
| 652 | // current flow control limits. Flow control should only be concerned with |
| 653 | // data that has actually been sent/received, so verify that flow control |
| 654 | // ignores such a stream frame. |
| 655 | Initialize(); |
| 656 | |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 657 | EXPECT_FALSE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 658 | const QuicStreamOffset kByteOffsetExceedingFlowControlWindow = |
| 659 | kInitialSessionFlowControlWindowForTest + 1; |
| 660 | const QuicStreamOffset current_stream_flow_control_offset = |
| 661 | QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()); |
| 662 | const QuicStreamOffset current_connection_flow_control_offset = |
| 663 | QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller()); |
| 664 | ASSERT_GT(kByteOffsetExceedingFlowControlWindow, |
| 665 | current_stream_flow_control_offset); |
| 666 | ASSERT_GT(kByteOffsetExceedingFlowControlWindow, |
| 667 | current_connection_flow_control_offset); |
| 668 | QuicStreamFrame zero_length_stream_frame_with_fin( |
| 669 | stream_->id(), /*fin=*/true, kByteOffsetExceedingFlowControlWindow, |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 670 | quiche::QuicheStringPiece()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 671 | EXPECT_EQ(0, zero_length_stream_frame_with_fin.data_length); |
| 672 | |
| 673 | EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| 674 | stream_->OnStreamFrame(zero_length_stream_frame_with_fin); |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 675 | EXPECT_TRUE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 676 | |
| 677 | // The flow control receive offset values should not have changed. |
| 678 | EXPECT_EQ( |
| 679 | current_stream_flow_control_offset, |
| 680 | QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller())); |
| 681 | EXPECT_EQ( |
| 682 | current_connection_flow_control_offset, |
| 683 | QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller())); |
| 684 | } |
| 685 | |
| 686 | TEST_P(QuicStreamTest, OnStreamResetOffsetOverflow) { |
| 687 | Initialize(); |
| 688 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(), |
| 689 | QUIC_STREAM_CANCELLED, kMaxStreamLength + 1); |
| 690 | EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _)); |
| 691 | stream_->OnStreamReset(rst_frame); |
| 692 | } |
| 693 | |
| 694 | TEST_P(QuicStreamTest, OnStreamFrameUpperLimit) { |
| 695 | Initialize(); |
| 696 | |
| 697 | // Modify receive window offset and sequencer buffer total_bytes_read_ to |
| 698 | // avoid flow control violation. |
| 699 | QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
| 700 | kMaxStreamLength + 5u); |
| 701 | QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(), |
| 702 | kMaxStreamLength + 5u); |
| 703 | QuicStreamSequencerPeer::SetFrameBufferTotalBytesRead( |
| 704 | QuicStreamPeer::sequencer(stream_), kMaxStreamLength - 10u); |
| 705 | |
| 706 | EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _)) |
| 707 | .Times(0); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 708 | QuicStreamFrame stream_frame(stream_->id(), false, kMaxStreamLength - 1, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 709 | stream_->OnStreamFrame(stream_frame); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 710 | QuicStreamFrame stream_frame2(stream_->id(), true, kMaxStreamLength, ""); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 711 | stream_->OnStreamFrame(stream_frame2); |
| 712 | } |
| 713 | |
| 714 | TEST_P(QuicStreamTest, StreamTooLong) { |
| 715 | Initialize(); |
| 716 | EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _)) |
| 717 | .Times(1); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 718 | QuicStreamFrame stream_frame(stream_->id(), false, kMaxStreamLength, "."); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 719 | EXPECT_QUIC_PEER_BUG( |
| 720 | stream_->OnStreamFrame(stream_frame), |
| 721 | quiche::QuicheStrCat("Receive stream frame on stream ", stream_->id(), |
| 722 | " reaches max stream length")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 723 | } |
| 724 | |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 725 | TEST_P(QuicStreamTest, SetDrainingIncomingOutgoing) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 726 | // Don't have incoming data consumed. |
| 727 | Initialize(); |
| 728 | |
| 729 | // Incoming data with FIN. |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 730 | QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 731 | stream_->OnStreamFrame(stream_frame_with_fin); |
| 732 | // The FIN has been received but not consumed. |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 733 | EXPECT_TRUE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 734 | EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 735 | EXPECT_FALSE(stream_->reading_stopped()); |
| 736 | |
| 737 | EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 738 | |
| 739 | // Outgoing data with FIN. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 740 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 741 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 742 | return session_->ConsumeData(stream_->id(), 2u, 0u, FIN, false, |
| 743 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 744 | })); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 745 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true, |
| 746 | nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 747 | EXPECT_TRUE(stream_->write_side_closed()); |
| 748 | |
| 749 | EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) |
| 750 | ->count(kTestStreamId)); |
| 751 | EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 752 | } |
| 753 | |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 754 | TEST_P(QuicStreamTest, SetDrainingOutgoingIncoming) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 755 | // Don't have incoming data consumed. |
| 756 | Initialize(); |
| 757 | |
| 758 | // Outgoing data with FIN. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 759 | EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 760 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 761 | return session_->ConsumeData(stream_->id(), 2u, 0u, FIN, false, |
| 762 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 763 | })); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 764 | stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true, |
| 765 | nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 766 | EXPECT_TRUE(stream_->write_side_closed()); |
| 767 | |
| 768 | EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 769 | |
| 770 | // Incoming data with FIN. |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 771 | QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, "."); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 772 | stream_->OnStreamFrame(stream_frame_with_fin); |
| 773 | // The FIN has been received but not consumed. |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 774 | EXPECT_TRUE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 775 | EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 776 | EXPECT_FALSE(stream_->reading_stopped()); |
| 777 | |
| 778 | EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) |
| 779 | ->count(kTestStreamId)); |
| 780 | EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
| 781 | } |
| 782 | |
| 783 | TEST_P(QuicStreamTest, EarlyResponseFinHandling) { |
| 784 | // Verify that if the server completes the response before reading the end of |
| 785 | // the request, the received FIN is recorded. |
| 786 | |
| 787 | Initialize(); |
| 788 | EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 789 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 790 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 791 | |
| 792 | // Receive data for the request. |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 793 | EXPECT_CALL(*stream_, OnDataAvailable()).Times(1); |
| 794 | QuicStreamFrame frame1(stream_->id(), false, 0, "Start"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 795 | stream_->OnStreamFrame(frame1); |
| 796 | // When QuicSimpleServerStream sends the response, it calls |
| 797 | // QuicStream::CloseReadSide() first. |
| 798 | QuicStreamPeer::CloseReadSide(stream_); |
| 799 | // Send data and FIN for the response. |
| 800 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 801 | EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
| 802 | // Receive remaining data and FIN for the request. |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 803 | QuicStreamFrame frame2(stream_->id(), true, 0, "End"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 804 | stream_->OnStreamFrame(frame2); |
| 805 | EXPECT_TRUE(stream_->fin_received()); |
renjietang | 6c06656 | 2019-11-04 17:05:59 -0800 | [diff] [blame] | 806 | EXPECT_TRUE(stream_->HasReceivedFinalOffset()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | TEST_P(QuicStreamTest, StreamWaitsForAcks) { |
| 810 | Initialize(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 811 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 812 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 813 | // Stream is not waiting for acks initially. |
| 814 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 815 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 816 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 817 | |
| 818 | // Send kData1. |
| 819 | stream_->WriteOrBufferData(kData1, false, nullptr); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 820 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 821 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 822 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 823 | QuicByteCount newly_acked_length = 0; |
| 824 | EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 825 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 826 | &newly_acked_length)); |
| 827 | EXPECT_EQ(9u, newly_acked_length); |
| 828 | // Stream is not waiting for acks as all sent data is acked. |
| 829 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 830 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 831 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 832 | |
| 833 | // Send kData2. |
| 834 | stream_->WriteOrBufferData(kData2, false, nullptr); |
| 835 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 836 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 837 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 838 | // Send FIN. |
| 839 | stream_->WriteOrBufferData("", true, nullptr); |
| 840 | // Fin only frame is not stored in send buffer. |
| 841 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 842 | |
| 843 | // kData2 is retransmitted. |
| 844 | stream_->OnStreamFrameRetransmitted(9, 9, false); |
| 845 | |
| 846 | // kData2 is acked. |
| 847 | EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 848 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 849 | &newly_acked_length)); |
| 850 | EXPECT_EQ(9u, newly_acked_length); |
| 851 | // Stream is waiting for acks as FIN is not acked. |
| 852 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 853 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 854 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 855 | |
| 856 | // FIN is acked. |
| 857 | EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 0, true, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 858 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 859 | &newly_acked_length)); |
| 860 | EXPECT_EQ(0u, newly_acked_length); |
| 861 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 862 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 863 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 864 | } |
| 865 | |
| 866 | TEST_P(QuicStreamTest, StreamDataGetAckedOutOfOrder) { |
| 867 | Initialize(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 868 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 869 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 870 | // Send data. |
| 871 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 872 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 873 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 874 | stream_->WriteOrBufferData("", true, nullptr); |
| 875 | EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 876 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 877 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 878 | QuicByteCount newly_acked_length = 0; |
| 879 | EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 880 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 881 | &newly_acked_length)); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 882 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 883 | EXPECT_EQ(9u, newly_acked_length); |
| 884 | EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 885 | EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 9, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 886 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 887 | &newly_acked_length)); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 888 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 889 | EXPECT_EQ(9u, newly_acked_length); |
| 890 | EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 891 | EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 892 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 893 | &newly_acked_length)); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 894 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 895 | EXPECT_EQ(9u, newly_acked_length); |
| 896 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 897 | // FIN is not acked yet. |
| 898 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 899 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 900 | EXPECT_TRUE(stream_->OnStreamFrameAcked(27, 0, true, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 901 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 902 | &newly_acked_length)); |
| 903 | EXPECT_EQ(0u, newly_acked_length); |
| 904 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 905 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | TEST_P(QuicStreamTest, CancelStream) { |
| 909 | Initialize(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 910 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 911 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 912 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 913 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 914 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 915 | |
| 916 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 917 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 918 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 919 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 920 | // Cancel stream. |
| 921 | stream_->Reset(QUIC_STREAM_NO_ERROR); |
| 922 | // stream still waits for acks as the error code is QUIC_STREAM_NO_ERROR, and |
| 923 | // data is going to be retransmitted. |
| 924 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 925 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 926 | EXPECT_CALL(*connection_, |
| 927 | OnStreamReset(stream_->id(), QUIC_STREAM_CANCELLED)); |
renjietang | eab9285 | 2019-10-25 12:16:14 -0700 | [diff] [blame] | 928 | EXPECT_CALL(*connection_, SendControlFrame(_)) |
| 929 | .Times(AtLeast(1)) |
| 930 | .WillRepeatedly(Invoke(&ClearControlFrame)); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 931 | EXPECT_CALL(*session_, SendRstStream(stream_->id(), QUIC_STREAM_CANCELLED, 9)) |
| 932 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 61cc245 | 2019-11-26 10:57:10 -0800 | [diff] [blame] | 933 | session_->ReallySendRstStream(stream_->id(), QUIC_STREAM_CANCELLED, |
| 934 | stream_->stream_bytes_written()); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 935 | })); |
| 936 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 937 | stream_->Reset(QUIC_STREAM_CANCELLED); |
| 938 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 939 | // Stream stops waiting for acks as data is not going to be retransmitted. |
| 940 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 941 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | TEST_P(QuicStreamTest, RstFrameReceivedStreamNotFinishSending) { |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 945 | if (VersionHasIetfQuicFrames(GetParam().transport_version)) { |
| 946 | // In IETF QUIC, receiving a RESET_STREAM will only close the read side. The |
| 947 | // stream itself is not closed and will not send reset. |
| 948 | return; |
| 949 | } |
| 950 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 951 | Initialize(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 952 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 953 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 954 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 955 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 956 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 957 | |
| 958 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 959 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 960 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 961 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 962 | |
| 963 | // RST_STREAM received. |
| 964 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(), |
| 965 | QUIC_STREAM_CANCELLED, 9); |
| 966 | EXPECT_CALL(*session_, |
| 967 | SendRstStream(stream_->id(), QUIC_RST_ACKNOWLEDGEMENT, 9)); |
| 968 | stream_->OnStreamReset(rst_frame); |
| 969 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 970 | // Stream stops waiting for acks as it does not finish sending and rst is |
| 971 | // sent. |
| 972 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 973 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | TEST_P(QuicStreamTest, RstFrameReceivedStreamFinishSending) { |
| 977 | Initialize(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 978 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 979 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 980 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 981 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 982 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 983 | |
| 984 | stream_->WriteOrBufferData(kData1, true, nullptr); |
| 985 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 986 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 987 | |
| 988 | // RST_STREAM received. |
| 989 | EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(0); |
| 990 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(), |
| 991 | QUIC_STREAM_CANCELLED, 1234); |
| 992 | stream_->OnStreamReset(rst_frame); |
| 993 | // Stream still waits for acks as it finishes sending and has unacked data. |
| 994 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 995 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 996 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 997 | } |
| 998 | |
| 999 | TEST_P(QuicStreamTest, ConnectionClosed) { |
| 1000 | Initialize(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1001 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1002 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1003 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 1004 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1005 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1006 | |
| 1007 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 1008 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 1009 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1010 | EXPECT_CALL(*session_, |
| 1011 | SendRstStream(stream_->id(), QUIC_RST_ACKNOWLEDGEMENT, 9)); |
| 1012 | stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, |
| 1013 | ConnectionCloseSource::FROM_SELF); |
| 1014 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1015 | // Stream stops waiting for acks as connection is going to close. |
| 1016 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 1017 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | TEST_P(QuicStreamTest, CanWriteNewDataAfterData) { |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 1021 | SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1022 | Initialize(); |
| 1023 | EXPECT_TRUE(stream_->CanWriteNewDataAfterData(99)); |
| 1024 | EXPECT_FALSE(stream_->CanWriteNewDataAfterData(100)); |
| 1025 | } |
| 1026 | |
| 1027 | TEST_P(QuicStreamTest, WriteBufferedData) { |
| 1028 | // Set buffered data low water mark to be 100. |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 1029 | SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1030 | |
| 1031 | Initialize(); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1032 | std::string data(1024, 'a'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1033 | EXPECT_TRUE(stream_->CanWriteNewData()); |
| 1034 | |
| 1035 | // Testing WriteOrBufferData. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1036 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1037 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1038 | return session_->ConsumeData(stream_->id(), 100u, 0u, NO_FIN, false, |
| 1039 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1040 | })); |
| 1041 | stream_->WriteOrBufferData(data, false, nullptr); |
| 1042 | stream_->WriteOrBufferData(data, false, nullptr); |
| 1043 | stream_->WriteOrBufferData(data, false, nullptr); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1044 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 1045 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1046 | // Verify all data is saved. |
| 1047 | EXPECT_EQ(3 * data.length() - 100, stream_->BufferedDataBytes()); |
| 1048 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1049 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1050 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1051 | return session_->ConsumeData(stream_->id(), 100, 100u, NO_FIN, false, |
| 1052 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1053 | })); |
| 1054 | // Buffered data size > threshold, do not ask upper layer for more data. |
| 1055 | EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(0); |
| 1056 | stream_->OnCanWrite(); |
| 1057 | EXPECT_EQ(3 * data.length() - 200, stream_->BufferedDataBytes()); |
| 1058 | EXPECT_FALSE(stream_->CanWriteNewData()); |
| 1059 | |
| 1060 | // Send buffered data to make buffered data size < threshold. |
| 1061 | size_t data_to_write = 3 * data.length() - 200 - |
| 1062 | GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1; |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1063 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1064 | .WillOnce(InvokeWithoutArgs([this, data_to_write]() { |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1065 | return session_->ConsumeData(stream_->id(), data_to_write, 200u, NO_FIN, |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1066 | false, QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1067 | })); |
| 1068 | // Buffered data size < threshold, ask upper layer for more data. |
| 1069 | EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1); |
| 1070 | stream_->OnCanWrite(); |
dschinazi | 696ee60 | 2019-04-25 16:05:35 -0700 | [diff] [blame] | 1071 | EXPECT_EQ(static_cast<uint64_t>( |
| 1072 | GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1073 | stream_->BufferedDataBytes()); |
| 1074 | EXPECT_TRUE(stream_->CanWriteNewData()); |
| 1075 | |
| 1076 | // Flush all buffered data. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1077 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1078 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1079 | EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1); |
| 1080 | stream_->OnCanWrite(); |
| 1081 | EXPECT_EQ(0u, stream_->BufferedDataBytes()); |
| 1082 | EXPECT_FALSE(stream_->HasBufferedData()); |
| 1083 | EXPECT_TRUE(stream_->CanWriteNewData()); |
| 1084 | |
| 1085 | // Testing Writev. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1086 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1087 | .WillOnce(Return(QuicConsumedData(0, false))); |
| 1088 | struct iovec iov = {const_cast<char*>(data.data()), data.length()}; |
| 1089 | QuicMemSliceStorage storage( |
| 1090 | &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(), |
| 1091 | 1024); |
| 1092 | QuicConsumedData consumed = stream_->WriteMemSlices(storage.ToSpan(), false); |
| 1093 | |
| 1094 | // There is no buffered data before, all data should be consumed without |
| 1095 | // respecting buffered data upper limit. |
| 1096 | EXPECT_EQ(data.length(), consumed.bytes_consumed); |
| 1097 | EXPECT_FALSE(consumed.fin_consumed); |
| 1098 | EXPECT_EQ(data.length(), stream_->BufferedDataBytes()); |
| 1099 | EXPECT_FALSE(stream_->CanWriteNewData()); |
| 1100 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1101 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1102 | QuicMemSliceStorage storage2( |
| 1103 | &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(), |
| 1104 | 1024); |
| 1105 | consumed = stream_->WriteMemSlices(storage2.ToSpan(), false); |
| 1106 | // No Data can be consumed as buffered data is beyond upper limit. |
| 1107 | EXPECT_EQ(0u, consumed.bytes_consumed); |
| 1108 | EXPECT_FALSE(consumed.fin_consumed); |
| 1109 | EXPECT_EQ(data.length(), stream_->BufferedDataBytes()); |
| 1110 | |
| 1111 | data_to_write = |
| 1112 | data.length() - GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1; |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1113 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1114 | .WillOnce(InvokeWithoutArgs([this, data_to_write]() { |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1115 | return session_->ConsumeData(stream_->id(), data_to_write, 0u, NO_FIN, |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1116 | false, QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1117 | })); |
| 1118 | |
| 1119 | EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1); |
| 1120 | stream_->OnCanWrite(); |
dschinazi | 696ee60 | 2019-04-25 16:05:35 -0700 | [diff] [blame] | 1121 | EXPECT_EQ(static_cast<uint64_t>( |
| 1122 | GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1123 | stream_->BufferedDataBytes()); |
| 1124 | EXPECT_TRUE(stream_->CanWriteNewData()); |
| 1125 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1126 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1127 | // All data can be consumed as buffered data is below upper limit. |
| 1128 | QuicMemSliceStorage storage3( |
| 1129 | &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(), |
| 1130 | 1024); |
| 1131 | consumed = stream_->WriteMemSlices(storage3.ToSpan(), false); |
| 1132 | EXPECT_EQ(data.length(), consumed.bytes_consumed); |
| 1133 | EXPECT_FALSE(consumed.fin_consumed); |
| 1134 | EXPECT_EQ(data.length() + GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1, |
| 1135 | stream_->BufferedDataBytes()); |
| 1136 | EXPECT_FALSE(stream_->CanWriteNewData()); |
| 1137 | } |
| 1138 | |
| 1139 | TEST_P(QuicStreamTest, WritevDataReachStreamLimit) { |
| 1140 | Initialize(); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1141 | std::string data("aaaaa"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1142 | QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - data.length(), |
| 1143 | stream_); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1144 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1145 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1146 | struct iovec iov = {const_cast<char*>(data.data()), 5u}; |
| 1147 | QuicMemSliceStorage storage( |
| 1148 | &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(), |
| 1149 | 1024); |
| 1150 | QuicConsumedData consumed = stream_->WriteMemSlices(storage.ToSpan(), false); |
| 1151 | EXPECT_EQ(data.length(), consumed.bytes_consumed); |
| 1152 | struct iovec iov2 = {const_cast<char*>(data.data()), 1u}; |
| 1153 | QuicMemSliceStorage storage2( |
| 1154 | &iov2, 1, |
| 1155 | session_->connection()->helper()->GetStreamSendBufferAllocator(), 1024); |
| 1156 | EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _)); |
| 1157 | EXPECT_QUIC_BUG(stream_->WriteMemSlices(storage2.ToSpan(), false), |
| 1158 | "Write too many data via stream"); |
| 1159 | } |
| 1160 | |
| 1161 | TEST_P(QuicStreamTest, WriteMemSlices) { |
| 1162 | // Set buffered data low water mark to be 100. |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 1163 | SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1164 | |
| 1165 | Initialize(); |
| 1166 | char data[1024]; |
| 1167 | std::vector<std::pair<char*, size_t>> buffers; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1168 | buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data))); |
| 1169 | buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1170 | QuicTestMemSliceVector vector1(buffers); |
| 1171 | QuicTestMemSliceVector vector2(buffers); |
| 1172 | QuicMemSliceSpan span1 = vector1.span(); |
| 1173 | QuicMemSliceSpan span2 = vector2.span(); |
| 1174 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1175 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1176 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1177 | return session_->ConsumeData(stream_->id(), 100u, 0u, NO_FIN, false, |
| 1178 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1179 | })); |
| 1180 | // There is no buffered data before, all data should be consumed. |
| 1181 | QuicConsumedData consumed = stream_->WriteMemSlices(span1, false); |
| 1182 | EXPECT_EQ(2048u, consumed.bytes_consumed); |
| 1183 | EXPECT_FALSE(consumed.fin_consumed); |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1184 | EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) - 100, stream_->BufferedDataBytes()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1185 | EXPECT_FALSE(stream_->fin_buffered()); |
| 1186 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1187 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1188 | // No Data can be consumed as buffered data is beyond upper limit. |
| 1189 | consumed = stream_->WriteMemSlices(span2, true); |
| 1190 | EXPECT_EQ(0u, consumed.bytes_consumed); |
| 1191 | EXPECT_FALSE(consumed.fin_consumed); |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1192 | EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) - 100, stream_->BufferedDataBytes()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1193 | EXPECT_FALSE(stream_->fin_buffered()); |
| 1194 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1195 | size_t data_to_write = 2 * QUICHE_ARRAYSIZE(data) - 100 - |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1196 | GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1; |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1197 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1198 | .WillOnce(InvokeWithoutArgs([this, data_to_write]() { |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1199 | return session_->ConsumeData(stream_->id(), data_to_write, 100u, NO_FIN, |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1200 | false, QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1201 | })); |
| 1202 | EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1); |
| 1203 | stream_->OnCanWrite(); |
dschinazi | 696ee60 | 2019-04-25 16:05:35 -0700 | [diff] [blame] | 1204 | EXPECT_EQ(static_cast<uint64_t>( |
| 1205 | GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1206 | stream_->BufferedDataBytes()); |
| 1207 | // Try to write slices2 again. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1208 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1209 | consumed = stream_->WriteMemSlices(span2, true); |
| 1210 | EXPECT_EQ(2048u, consumed.bytes_consumed); |
| 1211 | EXPECT_TRUE(consumed.fin_consumed); |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1212 | EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) + |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1213 | GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1, |
| 1214 | stream_->BufferedDataBytes()); |
| 1215 | EXPECT_TRUE(stream_->fin_buffered()); |
| 1216 | |
| 1217 | // Flush all buffered data. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1218 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1219 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1220 | stream_->OnCanWrite(); |
| 1221 | EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(0); |
| 1222 | EXPECT_FALSE(stream_->HasBufferedData()); |
| 1223 | EXPECT_TRUE(stream_->write_side_closed()); |
| 1224 | } |
| 1225 | |
| 1226 | TEST_P(QuicStreamTest, WriteMemSlicesReachStreamLimit) { |
| 1227 | Initialize(); |
| 1228 | QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - 5u, stream_); |
| 1229 | char data[5]; |
| 1230 | std::vector<std::pair<char*, size_t>> buffers; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1231 | buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1232 | QuicTestMemSliceVector vector1(buffers); |
| 1233 | QuicMemSliceSpan span1 = vector1.span(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1234 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1235 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1236 | return session_->ConsumeData(stream_->id(), 5u, 0u, NO_FIN, false, |
| 1237 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1238 | })); |
| 1239 | // There is no buffered data before, all data should be consumed. |
| 1240 | QuicConsumedData consumed = stream_->WriteMemSlices(span1, false); |
| 1241 | EXPECT_EQ(5u, consumed.bytes_consumed); |
| 1242 | |
| 1243 | std::vector<std::pair<char*, size_t>> buffers2; |
| 1244 | buffers2.push_back(std::make_pair(data, 1u)); |
| 1245 | QuicTestMemSliceVector vector2(buffers); |
| 1246 | QuicMemSliceSpan span2 = vector2.span(); |
| 1247 | EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _)); |
| 1248 | EXPECT_QUIC_BUG(stream_->WriteMemSlices(span2, false), |
| 1249 | "Write too many data via stream"); |
| 1250 | } |
| 1251 | |
| 1252 | TEST_P(QuicStreamTest, StreamDataGetAckedMultipleTimes) { |
| 1253 | Initialize(); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1254 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1255 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1256 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 1257 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1258 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1259 | // Send [0, 27) and fin. |
| 1260 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 1261 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 1262 | stream_->WriteOrBufferData(kData1, true, nullptr); |
| 1263 | EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1264 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 1265 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1266 | // Ack [0, 9), [5, 22) and [18, 26) |
| 1267 | // Verify [0, 9) 9 bytes are acked. |
| 1268 | QuicByteCount newly_acked_length = 0; |
| 1269 | EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1270 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1271 | &newly_acked_length)); |
| 1272 | EXPECT_EQ(9u, newly_acked_length); |
| 1273 | EXPECT_EQ(2u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1274 | // Verify [9, 22) 13 bytes are acked. |
| 1275 | EXPECT_TRUE(stream_->OnStreamFrameAcked(5, 17, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1276 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1277 | &newly_acked_length)); |
| 1278 | EXPECT_EQ(13u, newly_acked_length); |
| 1279 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1280 | // Verify [22, 26) 4 bytes are acked. |
| 1281 | EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 8, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1282 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1283 | &newly_acked_length)); |
| 1284 | EXPECT_EQ(4u, newly_acked_length); |
| 1285 | EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1286 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 1287 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1288 | |
| 1289 | // Ack [0, 27). Verify [26, 27) 1 byte is acked. |
| 1290 | EXPECT_TRUE(stream_->OnStreamFrameAcked(26, 1, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1291 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1292 | &newly_acked_length)); |
| 1293 | EXPECT_EQ(1u, newly_acked_length); |
| 1294 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1295 | EXPECT_TRUE(stream_->IsWaitingForAcks()); |
fayang | 8265a2a | 2019-10-16 11:23:51 -0700 | [diff] [blame] | 1296 | EXPECT_TRUE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1297 | |
| 1298 | // Ack Fin. |
| 1299 | EXPECT_TRUE(stream_->OnStreamFrameAcked(27, 0, true, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1300 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1301 | &newly_acked_length)); |
| 1302 | EXPECT_EQ(0u, newly_acked_length); |
| 1303 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1304 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 1305 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1306 | |
| 1307 | // Ack [10, 27) and fin. No new data is acked. |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1308 | EXPECT_FALSE( |
| 1309 | stream_->OnStreamFrameAcked(10, 17, true, QuicTime::Delta::Zero(), |
| 1310 | QuicTime::Zero(), &newly_acked_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1311 | EXPECT_EQ(0u, newly_acked_length); |
| 1312 | EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size()); |
| 1313 | EXPECT_FALSE(stream_->IsWaitingForAcks()); |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 1314 | EXPECT_FALSE(session_->HasUnackedStreamData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | TEST_P(QuicStreamTest, OnStreamFrameLost) { |
| 1318 | Initialize(); |
| 1319 | |
| 1320 | // Send [0, 9). |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1321 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1322 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1323 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 1324 | EXPECT_FALSE(stream_->HasBufferedData()); |
| 1325 | EXPECT_TRUE(stream_->IsStreamFrameOutstanding(0, 9, false)); |
| 1326 | |
| 1327 | // Try to send [9, 27), but connection is blocked. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1328 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1329 | .WillOnce(Return(QuicConsumedData(0, false))); |
| 1330 | stream_->WriteOrBufferData(kData2, false, nullptr); |
| 1331 | stream_->WriteOrBufferData(kData2, false, nullptr); |
| 1332 | EXPECT_TRUE(stream_->HasBufferedData()); |
| 1333 | EXPECT_FALSE(stream_->HasPendingRetransmission()); |
| 1334 | |
| 1335 | // Lost [0, 9). When stream gets a chance to write, only lost data is |
| 1336 | // transmitted. |
| 1337 | stream_->OnStreamFrameLost(0, 9, false); |
| 1338 | EXPECT_TRUE(stream_->HasPendingRetransmission()); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1339 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1340 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 1341 | EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1342 | stream_->OnCanWrite(); |
| 1343 | EXPECT_FALSE(stream_->HasPendingRetransmission()); |
| 1344 | EXPECT_TRUE(stream_->HasBufferedData()); |
| 1345 | |
| 1346 | // This OnCanWrite causes [9, 27) to be sent. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1347 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1348 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1349 | stream_->OnCanWrite(); |
| 1350 | EXPECT_FALSE(stream_->HasBufferedData()); |
| 1351 | |
| 1352 | // Send a fin only frame. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1353 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1354 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1355 | stream_->WriteOrBufferData("", true, nullptr); |
| 1356 | |
| 1357 | // Lost [9, 27) and fin. |
| 1358 | stream_->OnStreamFrameLost(9, 18, false); |
| 1359 | stream_->OnStreamFrameLost(27, 0, true); |
| 1360 | EXPECT_TRUE(stream_->HasPendingRetransmission()); |
| 1361 | |
| 1362 | // Ack [9, 18). |
| 1363 | QuicByteCount newly_acked_length = 0; |
| 1364 | EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1365 | QuicTime::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1366 | &newly_acked_length)); |
| 1367 | EXPECT_EQ(9u, newly_acked_length); |
| 1368 | EXPECT_FALSE(stream_->IsStreamFrameOutstanding(9, 3, false)); |
| 1369 | EXPECT_TRUE(stream_->HasPendingRetransmission()); |
| 1370 | // This OnCanWrite causes [18, 27) and fin to be retransmitted. Verify fin can |
| 1371 | // be bundled with data. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1372 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1373 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1374 | return session_->ConsumeData(stream_->id(), 9u, 18u, FIN, false, |
| 1375 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1376 | })); |
| 1377 | stream_->OnCanWrite(); |
| 1378 | EXPECT_FALSE(stream_->HasPendingRetransmission()); |
| 1379 | // Lost [9, 18) again, but it is not considered as lost because kData2 |
| 1380 | // has been acked. |
| 1381 | stream_->OnStreamFrameLost(9, 9, false); |
| 1382 | EXPECT_FALSE(stream_->HasPendingRetransmission()); |
| 1383 | EXPECT_TRUE(stream_->IsStreamFrameOutstanding(27, 0, true)); |
| 1384 | } |
| 1385 | |
| 1386 | TEST_P(QuicStreamTest, CannotBundleLostFin) { |
| 1387 | Initialize(); |
| 1388 | |
| 1389 | // Send [0, 18) and fin. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1390 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1391 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1392 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 1393 | stream_->WriteOrBufferData(kData2, true, nullptr); |
| 1394 | |
| 1395 | // Lost [0, 9) and fin. |
| 1396 | stream_->OnStreamFrameLost(0, 9, false); |
| 1397 | stream_->OnStreamFrameLost(18, 0, true); |
| 1398 | |
| 1399 | // Retransmit lost data. Verify [0, 9) and fin are retransmitted in two |
| 1400 | // frames. |
| 1401 | InSequence s; |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1402 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1403 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1404 | return session_->ConsumeData(stream_->id(), 9u, 0u, NO_FIN, false, |
| 1405 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1406 | })); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1407 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1408 | .WillOnce(Return(QuicConsumedData(0, true))); |
| 1409 | stream_->OnCanWrite(); |
| 1410 | } |
| 1411 | |
| 1412 | TEST_P(QuicStreamTest, MarkConnectionLevelWriteBlockedOnWindowUpdateFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1413 | Initialize(); |
| 1414 | |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1415 | // Set the config to a small value so that a newly created stream has small |
| 1416 | // send flow control window. |
| 1417 | QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_->config(), |
| 1418 | 100); |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 1419 | QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional( |
| 1420 | session_->config(), 100); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1421 | auto stream = new TestStream(GetNthClientInitiatedBidirectionalStreamId( |
| 1422 | GetParam().transport_version, 2), |
| 1423 | session_.get(), BIDIRECTIONAL); |
| 1424 | session_->ActivateStream(QuicWrapUnique(stream)); |
| 1425 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1426 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1427 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1428 | EXPECT_CALL(*connection_, SendControlFrame(_)) |
bnc | 5b3c3be | 2019-06-25 10:37:09 -0700 | [diff] [blame] | 1429 | .WillOnce(Invoke(&ClearControlFrame)); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1430 | std::string data(1024, '.'); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1431 | stream->WriteOrBufferData(data, false, nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1432 | EXPECT_FALSE(HasWriteBlockedStreams()); |
| 1433 | |
| 1434 | QuicWindowUpdateFrame window_update(kInvalidControlFrameId, stream_->id(), |
| 1435 | 1234); |
| 1436 | |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1437 | stream->OnWindowUpdateFrame(window_update); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1438 | // Verify stream is marked connection level write blocked. |
| 1439 | EXPECT_TRUE(HasWriteBlockedStreams()); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1440 | EXPECT_TRUE(stream->HasBufferedData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | // Regression test for b/73282665. |
| 1444 | TEST_P(QuicStreamTest, |
| 1445 | MarkConnectionLevelWriteBlockedOnWindowUpdateFrameWithNoBufferedData) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1446 | Initialize(); |
| 1447 | |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1448 | // Set the config to a small value so that a newly created stream has small |
| 1449 | // send flow control window. |
| 1450 | QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_->config(), |
| 1451 | 100); |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 1452 | QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional( |
| 1453 | session_->config(), 100); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1454 | auto stream = new TestStream(GetNthClientInitiatedBidirectionalStreamId( |
| 1455 | GetParam().transport_version, 2), |
| 1456 | session_.get(), BIDIRECTIONAL); |
| 1457 | session_->ActivateStream(QuicWrapUnique(stream)); |
| 1458 | |
| 1459 | std::string data(100, '.'); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1460 | EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1461 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1462 | EXPECT_CALL(*connection_, SendControlFrame(_)) |
bnc | 5b3c3be | 2019-06-25 10:37:09 -0700 | [diff] [blame] | 1463 | .WillOnce(Invoke(&ClearControlFrame)); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1464 | stream->WriteOrBufferData(data, false, nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1465 | EXPECT_FALSE(HasWriteBlockedStreams()); |
| 1466 | |
| 1467 | QuicWindowUpdateFrame window_update(kInvalidControlFrameId, stream_->id(), |
| 1468 | 120); |
renjietang | 39979d3 | 2019-09-13 10:02:13 -0700 | [diff] [blame] | 1469 | stream->OnWindowUpdateFrame(window_update); |
| 1470 | EXPECT_FALSE(stream->HasBufferedData()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1471 | // Verify stream is marked as blocked although there is no buffered data. |
| 1472 | EXPECT_TRUE(HasWriteBlockedStreams()); |
| 1473 | } |
| 1474 | |
| 1475 | TEST_P(QuicStreamTest, RetransmitStreamData) { |
| 1476 | Initialize(); |
| 1477 | InSequence s; |
| 1478 | |
| 1479 | // Send [0, 18) with fin. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1480 | EXPECT_CALL(*session_, WritevData(stream_->id(), _, _, _, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1481 | .Times(2) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1482 | .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1483 | stream_->WriteOrBufferData(kData1, false, nullptr); |
| 1484 | stream_->WriteOrBufferData(kData1, true, nullptr); |
| 1485 | // Ack [10, 13). |
| 1486 | QuicByteCount newly_acked_length = 0; |
| 1487 | stream_->OnStreamFrameAcked(10, 3, false, QuicTime::Delta::Zero(), |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 1488 | QuicTime::Zero(), &newly_acked_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1489 | EXPECT_EQ(3u, newly_acked_length); |
| 1490 | // Retransmit [0, 18) with fin, and only [0, 8) is consumed. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1491 | EXPECT_CALL(*session_, WritevData(stream_->id(), 10, 0, NO_FIN, _, _)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1492 | .WillOnce(InvokeWithoutArgs([this]() { |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1493 | return session_->ConsumeData(stream_->id(), 8, 0u, NO_FIN, false, |
| 1494 | QuicheNullOpt); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1495 | })); |
| 1496 | EXPECT_FALSE(stream_->RetransmitStreamData(0, 18, true)); |
| 1497 | |
| 1498 | // Retransmit [0, 18) with fin, and all is consumed. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1499 | EXPECT_CALL(*session_, WritevData(stream_->id(), 10, 0, NO_FIN, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1500 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1501 | EXPECT_CALL(*session_, WritevData(stream_->id(), 5, 13, FIN, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1502 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1503 | EXPECT_TRUE(stream_->RetransmitStreamData(0, 18, true)); |
| 1504 | |
| 1505 | // Retransmit [0, 8) with fin, and all is consumed. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1506 | EXPECT_CALL(*session_, WritevData(stream_->id(), 8, 0, NO_FIN, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1507 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1508 | EXPECT_CALL(*session_, WritevData(stream_->id(), 0, 18, FIN, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1509 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1510 | EXPECT_TRUE(stream_->RetransmitStreamData(0, 8, true)); |
| 1511 | } |
| 1512 | |
| 1513 | TEST_P(QuicStreamTest, ResetStreamOnTtlExpiresRetransmitLostData) { |
| 1514 | Initialize(); |
| 1515 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1516 | EXPECT_CALL(*session_, WritevData(stream_->id(), 200, 0, FIN, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1517 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1518 | std::string body(200, 'a'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1519 | stream_->WriteOrBufferData(body, true, nullptr); |
| 1520 | |
| 1521 | // Set TTL to be 1 s. |
| 1522 | QuicTime::Delta ttl = QuicTime::Delta::FromSeconds(1); |
| 1523 | ASSERT_TRUE(stream_->MaybeSetTtl(ttl)); |
| 1524 | // Verify data gets retransmitted because TTL does not expire. |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1525 | EXPECT_CALL(*session_, WritevData(stream_->id(), 100, 0, NO_FIN, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1526 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1527 | EXPECT_TRUE(stream_->RetransmitStreamData(0, 100, false)); |
| 1528 | stream_->OnStreamFrameLost(100, 100, true); |
| 1529 | EXPECT_TRUE(stream_->HasPendingRetransmission()); |
| 1530 | |
| 1531 | connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 1532 | // Verify stream gets reset because TTL expires. |
| 1533 | EXPECT_CALL(*session_, SendRstStream(_, QUIC_STREAM_TTL_EXPIRED, _)).Times(1); |
| 1534 | stream_->OnCanWrite(); |
| 1535 | } |
| 1536 | |
| 1537 | TEST_P(QuicStreamTest, ResetStreamOnTtlExpiresEarlyRetransmitData) { |
| 1538 | Initialize(); |
| 1539 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame^] | 1540 | EXPECT_CALL(*session_, WritevData(stream_->id(), 200, 0, FIN, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 1541 | .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData)); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1542 | std::string body(200, 'a'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1543 | stream_->WriteOrBufferData(body, true, nullptr); |
| 1544 | |
| 1545 | // Set TTL to be 1 s. |
| 1546 | QuicTime::Delta ttl = QuicTime::Delta::FromSeconds(1); |
| 1547 | ASSERT_TRUE(stream_->MaybeSetTtl(ttl)); |
| 1548 | |
| 1549 | connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 1550 | // Verify stream gets reset because TTL expires. |
| 1551 | EXPECT_CALL(*session_, SendRstStream(_, QUIC_STREAM_TTL_EXPIRED, _)).Times(1); |
| 1552 | stream_->RetransmitStreamData(0, 100, false); |
| 1553 | } |
| 1554 | |
| 1555 | // Test that QuicStream::StopSending A) is a no-op if the connection is not in |
| 1556 | // version 99, B) that it properly invokes QuicSession::StopSending, and C) that |
| 1557 | // the correct data is passed along, including getting the stream ID. |
renjietang | 9bf2564 | 2019-10-10 10:21:15 -0700 | [diff] [blame] | 1558 | TEST_P(QuicStreamTest, CheckStopSending) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1559 | Initialize(); |
| 1560 | const int kStopSendingCode = 123; |
| 1561 | // These must start as false. |
bnc | c7d9e0c | 2019-04-16 10:22:15 -0700 | [diff] [blame] | 1562 | EXPECT_FALSE(stream_->write_side_closed()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1563 | EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 1564 | // Expect to actually see a stop sending if and only if we are in version 99. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 1565 | if (VersionHasIetfQuicFrames(connection_->transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1566 | EXPECT_CALL(*session_, SendStopSending(kStopSendingCode, stream_->id())) |
| 1567 | .Times(1); |
| 1568 | } else { |
| 1569 | EXPECT_CALL(*session_, SendStopSending(_, _)).Times(0); |
| 1570 | } |
| 1571 | stream_->SendStopSending(kStopSendingCode); |
| 1572 | // Sending a STOP_SENDING does not actually close the local stream. |
| 1573 | // Our implementation waits for the responding RESET_STREAM to effect the |
| 1574 | // closes. Therefore, read- and write-side closes should both be false. |
bnc | c7d9e0c | 2019-04-16 10:22:15 -0700 | [diff] [blame] | 1575 | EXPECT_FALSE(stream_->write_side_closed()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1576 | EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 1577 | } |
| 1578 | |
| 1579 | // Test that OnStreamReset does one-way (read) closes if version 99, two way |
| 1580 | // (read and write) if not version 99. |
| 1581 | TEST_P(QuicStreamTest, OnStreamResetReadOrReadWrite) { |
| 1582 | Initialize(); |
bnc | c7d9e0c | 2019-04-16 10:22:15 -0700 | [diff] [blame] | 1583 | EXPECT_FALSE(stream_->write_side_closed()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1584 | EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 1585 | |
| 1586 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(), |
| 1587 | QUIC_STREAM_CANCELLED, 1234); |
| 1588 | stream_->OnStreamReset(rst_frame); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 1589 | if (VersionHasIetfQuicFrames(connection_->transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1590 | // Version 99/IETF QUIC should close just the read side. |
| 1591 | EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
bnc | c7d9e0c | 2019-04-16 10:22:15 -0700 | [diff] [blame] | 1592 | EXPECT_FALSE(stream_->write_side_closed()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1593 | } else { |
| 1594 | // Google QUIC should close both sides of the stream. |
bnc | c7d9e0c | 2019-04-16 10:22:15 -0700 | [diff] [blame] | 1595 | EXPECT_TRUE(stream_->write_side_closed()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1596 | EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
| 1597 | } |
| 1598 | } |
| 1599 | |
renjietang | 28c04b7 | 2019-07-01 15:08:09 -0700 | [diff] [blame] | 1600 | TEST_P(QuicStreamTest, WindowUpdateForReadOnlyStream) { |
renjietang | 28c04b7 | 2019-07-01 15:08:09 -0700 | [diff] [blame] | 1601 | Initialize(); |
| 1602 | |
| 1603 | QuicStreamId stream_id = QuicUtils::GetFirstUnidirectionalStreamId( |
| 1604 | connection_->transport_version(), Perspective::IS_CLIENT); |
| 1605 | TestStream stream(stream_id, session_.get(), READ_UNIDIRECTIONAL); |
| 1606 | QuicWindowUpdateFrame window_update_frame(kInvalidControlFrameId, stream_id, |
| 1607 | 0); |
| 1608 | EXPECT_CALL( |
| 1609 | *connection_, |
| 1610 | CloseConnection( |
| 1611 | QUIC_WINDOW_UPDATE_RECEIVED_ON_READ_UNIDIRECTIONAL_STREAM, |
| 1612 | "WindowUpdateFrame received on READ_UNIDIRECTIONAL stream.", _)); |
| 1613 | stream.OnWindowUpdateFrame(window_update_frame); |
| 1614 | } |
| 1615 | |
renjietang | 15afba3 | 2019-10-23 14:32:35 -0700 | [diff] [blame] | 1616 | TEST_P(QuicStreamTest, RstStreamFrameChangesCloseOffset) { |
renjietang | 15afba3 | 2019-10-23 14:32:35 -0700 | [diff] [blame] | 1617 | Initialize(); |
| 1618 | |
| 1619 | QuicStreamFrame stream_frame(stream_->id(), true, 0, "abc"); |
renjietang | b38e635 | 2019-10-24 09:38:20 -0700 | [diff] [blame] | 1620 | EXPECT_CALL(*stream_, OnDataAvailable()); |
renjietang | 15afba3 | 2019-10-23 14:32:35 -0700 | [diff] [blame] | 1621 | stream_->OnStreamFrame(stream_frame); |
| 1622 | QuicRstStreamFrame rst(kInvalidControlFrameId, stream_->id(), |
| 1623 | QUIC_STREAM_CANCELLED, 0u); |
| 1624 | |
| 1625 | EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_MULTIPLE_OFFSET, _, _)); |
| 1626 | stream_->OnStreamReset(rst); |
| 1627 | } |
| 1628 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1629 | } // namespace |
| 1630 | } // namespace test |
| 1631 | } // namespace quic |