blob: 356a77d2f59ae7cb6fd592ce4cd9f0b889951a18 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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>
vasilvv872e7a32019-03-12 16:42:44 -07008#include <string>
bnc463f2352019-10-10 04:49:34 -07009#include <utility>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
renjietang15afba32019-10-23 14:32:35 -070011#include "net/third_party/quiche/src/quic/core/frames/quic_rst_stream_frame.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050012#include "net/third_party/quiche/src/quic/core/quic_connection.h"
renjietang39979d32019-09-13 10:02:13 -070013#include "net/third_party/quiche/src/quic/core/quic_constants.h"
renjietang15afba32019-10-23 14:32:35 -070014#include "net/third_party/quiche/src/quic/core/quic_error_codes.h"
renjietang39979d32019-09-13 10:02:13 -070015#include "net/third_party/quiche/src/quic/core/quic_types.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050016#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 teama6ef0a62019-03-07 20:34:33 -050019#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 teama6ef0a62019-03-07 20:34:33 -050024#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"
bnc4e9283d2019-12-17 07:08:57 -080033#include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h"
renjietang41a1b412020-02-27 15:05:14 -080034#include "net/third_party/quiche/src/common/platform/api/quiche_optional.h"
dmcardlecf0bfcf2019-12-13 08:08:21 -080035#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050036
37using testing::_;
38using testing::AnyNumber;
39using testing::AtLeast;
40using testing::InSequence;
41using testing::Invoke;
42using testing::InvokeWithoutArgs;
43using testing::Return;
44using testing::StrictMock;
45
46namespace quic {
47namespace test {
48namespace {
49
50const char kData1[] = "FooAndBar";
51const char kData2[] = "EepAndBaz";
dschinazif1e7b422020-04-30 12:21:28 -070052const QuicByteCount kDataLen = 9;
QUICHE teama6ef0a62019-03-07 20:34:33 -050053
54class TestStream : public QuicStream {
55 public:
56 TestStream(QuicStreamId id, QuicSession* session, StreamType type)
renjietangb38e6352019-10-24 09:38:20 -070057 : QuicStream(id, session, /*is_static=*/false, type) {
58 sequencer()->set_level_triggered(true);
59 }
QUICHE teama6ef0a62019-03-07 20:34:33 -050060
renjietangbaea59c2019-05-29 15:08:14 -070061 TestStream(PendingStream* pending, StreamType type, bool is_static)
62 : QuicStream(pending, type, is_static) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -050063
wub713afae2020-04-27 07:48:31 -070064 MOCK_METHOD(void, OnDataAvailable, (), (override));
QUICHE teama6ef0a62019-03-07 20:34:33 -050065
wub713afae2020-04-27 07:48:31 -070066 MOCK_METHOD(void, OnCanWriteNewData, (), (override));
QUICHE teama6ef0a62019-03-07 20:34:33 -050067
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 teama6ef0a62019-03-07 20:34:33 -050075
76 private:
vasilvvc48c8712019-03-11 13:38:16 -070077 std::string data_;
QUICHE teama6ef0a62019-03-07 20:34:33 -050078};
79
renjietang9bf25642019-10-10 10:21:15 -070080class QuicStreamTest : public QuicTestWithParam<ParsedQuicVersion> {
QUICHE teama6ef0a62019-03-07 20:34:33 -050081 public:
renjietang9bf25642019-10-10 10:21:15 -070082 QuicStreamTest()
renjietang39979d32019-09-13 10:02:13 -070083 : zero_(QuicTime::Delta::Zero()),
QUICHE teama6ef0a62019-03-07 20:34:33 -050084 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));
vasilvv0fc587f2019-09-06 13:33:08 -070092 session_ = std::make_unique<StrictMock<MockQuicSession>>(connection_);
renjietang39979d32019-09-13 10:02:13 -070093 session_->Initialize();
QUICHE teama6ef0a62019-03-07 20:34:33 -050094
renjietang39979d32019-09-13 10:02:13 -070095 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(
96 session_->config(), kMinimumFlowControlSendWindow);
dschinazi18cdf132019-10-09 16:08:18 -070097 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesUnidirectional(
98 session_->config(), kMinimumFlowControlSendWindow);
99 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional(
100 session_->config(), kMinimumFlowControlSendWindow);
101 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesOutgoingBidirectional(
102 session_->config(), kMinimumFlowControlSendWindow);
renjietange6d94672020-01-07 10:30:10 -0800103 QuicConfigPeer::SetReceivedMaxUnidirectionalStreams(session_->config(), 10);
renjietang39979d32019-09-13 10:02:13 -0700104 session_->OnConfigNegotiated();
QUICHE teama6ef0a62019-03-07 20:34:33 -0500105
renjietangb38e6352019-10-24 09:38:20 -0700106 stream_ = new StrictMock<TestStream>(kTestStreamId, session_.get(),
107 BIDIRECTIONAL);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500108 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
bncc7d9e0c2019-04-16 10:22:15 -0700118 bool fin_sent() { return stream_->fin_sent(); }
119 bool rst_sent() { return stream_->rst_sent(); }
QUICHE teama6ef0a62019-03-07 20:34:33 -0500120
QUICHE teama6ef0a62019-03-07 20:34:33 -0500121 bool HasWriteBlockedStreams() {
122 return write_blocked_list_->HasWriteBlockedSpecialStream() ||
123 write_blocked_list_->HasWriteBlockedDataStreams();
124 }
125
renjietang41a1b412020-02-27 15:05:14 -0800126 QuicConsumedData CloseStreamOnWriteError(
127 QuicStreamId id,
dschinazif1e7b422020-04-30 12:21:28 -0700128 QuicByteCount /*write_length*/,
renjietang41a1b412020-02-27 15:05:14 -0800129 QuicStreamOffset /*offset*/,
130 StreamSendingState /*state*/,
renjietang4d992bf2020-03-03 13:01:55 -0800131 TransmissionType /*type*/,
renjietang41a1b412020-02-27 15:05:14 -0800132 quiche::QuicheOptional<EncryptionLevel> /*level*/) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500133 session_->CloseStream(id);
134 return QuicConsumedData(1, false);
135 }
136
QUICHE teama6ef0a62019-03-07 20:34:33 -0500137 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_;
renjietangb38e6352019-10-24 09:38:20 -0700154 StrictMock<TestStream>* stream_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500155 QuicWriteBlockedList* write_blocked_list_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500156 QuicTime::Delta zero_;
157 ParsedQuicVersionVector supported_versions_;
renjietang940a5322019-08-02 16:17:51 -0700158 QuicStreamId kTestStreamId =
159 GetNthClientInitiatedBidirectionalStreamId(GetParam().transport_version,
160 1);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500161};
162
renjietang9bf25642019-10-10 10:21:15 -0700163INSTANTIATE_TEST_SUITE_P(QuicStreamTests,
164 QuicStreamTest,
dschinazi142051a2019-09-18 18:17:29 -0700165 ::testing::ValuesIn(AllSupportedVersions()),
166 ::testing::PrintToStringParamName());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500167
renjietang35448992019-05-08 17:08:57 -0700168TEST_P(QuicStreamTest, PendingStreamStaticness) {
169 Initialize();
170
171 PendingStream pending(kTestStreamId + 2, session_.get());
renjietangbaea59c2019-05-29 15:08:14 -0700172 TestStream stream(&pending, StreamType::BIDIRECTIONAL, false);
renjietang35448992019-05-08 17:08:57 -0700173 EXPECT_FALSE(stream.is_static());
174
175 PendingStream pending2(kTestStreamId + 3, session_.get());
renjietangbaea59c2019-05-29 15:08:14 -0700176 TestStream stream2(&pending2, StreamType::BIDIRECTIONAL, true);
renjietang35448992019-05-08 17:08:57 -0700177 EXPECT_TRUE(stream2.is_static());
178}
179
QUICHE teama6ef0a62019-03-07 20:34:33 -0500180TEST_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,
renjietangb38e6352019-10-24 09:38:20 -0700187 kInitialSessionFlowControlWindowForTest + 1, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500188
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
195TEST_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
212TEST_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
225TEST_P(QuicStreamTest, FromPendingStream) {
226 Initialize();
227
228 PendingStream pending(kTestStreamId + 2, session_.get());
229
renjietangb38e6352019-10-24 09:38:20 -0700230 QuicStreamFrame frame(kTestStreamId + 2, false, 2, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500231 pending.OnStreamFrame(frame);
232 pending.OnStreamFrame(frame);
renjietangb38e6352019-10-24 09:38:20 -0700233 QuicStreamFrame frame2(kTestStreamId + 2, true, 3, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500234 pending.OnStreamFrame(frame2);
235
renjietangbaea59c2019-05-29 15:08:14 -0700236 TestStream stream(&pending, StreamType::READ_UNIDIRECTIONAL, false);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500237 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
247TEST_P(QuicStreamTest, FromPendingStreamThenData) {
248 Initialize();
249
250 PendingStream pending(kTestStreamId + 2, session_.get());
251
renjietangb38e6352019-10-24 09:38:20 -0700252 QuicStreamFrame frame(kTestStreamId + 2, false, 2, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500253 pending.OnStreamFrame(frame);
254
renjietangbaea59c2019-05-29 15:08:14 -0700255 auto stream =
256 new TestStream(&pending, StreamType::READ_UNIDIRECTIONAL, false);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500257 session_->ActivateStream(QuicWrapUnique(stream));
258
renjietangb38e6352019-10-24 09:38:20 -0700259 QuicStreamFrame frame2(kTestStreamId + 2, true, 3, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500260 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
271TEST_P(QuicStreamTest, WriteAllData) {
272 Initialize();
273
dschinazif1e7b422020-04-30 12:21:28 -0700274 QuicByteCount length =
QUICHE teama6ef0a62019-03-07 20:34:33 -0500275 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
renjietang41a1b412020-02-27 15:05:14 -0800283 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800284 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500285 stream_->WriteOrBufferData(kData1, false, nullptr);
286 EXPECT_FALSE(HasWriteBlockedStreams());
287}
288
289TEST_P(QuicStreamTest, NoBlockingIfNoDataOrFin) {
290 Initialize();
291
292 // Write no data and no fin. If we consume nothing we should not be write
293 // blocked.
dmcardlecf0bfcf2019-12-13 08:08:21 -0800294 EXPECT_QUIC_BUG(
295 stream_->WriteOrBufferData(quiche::QuicheStringPiece(), false, nullptr),
296 "");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500297 EXPECT_FALSE(HasWriteBlockedStreams());
298}
299
300TEST_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.
renjietang41a1b412020-02-27 15:05:14 -0800305 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500306 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800307 return session_->ConsumeData(stream_->id(), 1u, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -0700308 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500309 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800310 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), false,
311 nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700312 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500313 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
314 EXPECT_EQ(1u, stream_->BufferedDataBytes());
315}
316
317TEST_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)
renjietang41a1b412020-02-27 15:05:14 -0800324 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500325 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800326 return session_->ConsumeData(stream_->id(), 2u, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -0700327 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500328 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800329 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true,
330 nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700331 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500332 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
333}
334
335TEST_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.
renjietang41a1b412020-02-27 15:05:14 -0800340 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500341 .WillOnce(Return(QuicConsumedData(0, false)));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800342 stream_->WriteOrBufferData(quiche::QuicheStringPiece(), true, nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500343 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
344}
345
346TEST_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.
renjietang41a1b412020-02-27 15:05:14 -0800352 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500353 .WillOnce(Invoke(this, &QuicStreamTest::CloseStreamOnWriteError));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800354 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), false,
355 nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500356 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams());
357}
358
359TEST_P(QuicStreamTest, WriteOrBufferData) {
360 Initialize();
361
362 EXPECT_FALSE(HasWriteBlockedStreams());
dschinazif1e7b422020-04-30 12:21:28 -0700363 QuicByteCount length =
QUICHE teama6ef0a62019-03-07 20:34:33 -0500364 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
renjietang41a1b412020-02-27 15:05:14 -0800372 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500373 .WillOnce(InvokeWithoutArgs([this]() {
renjietang7c239172020-02-21 13:50:39 -0800374 return session_->ConsumeData(stream_->id(), kDataLen - 1, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -0700375 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500376 }));
377 stream_->WriteOrBufferData(kData1, false, nullptr);
zhongyi1b2f7832019-06-14 13:31:34 -0700378
fayang8265a2a2019-10-16 11:23:51 -0700379 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500380 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;
renjietang41a1b412020-02-27 15:05:14 -0800388 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500389 .WillOnce(InvokeWithoutArgs([this]() {
renjietang7c239172020-02-21 13:50:39 -0800390 return session_->ConsumeData(stream_->id(), kDataLen - 1, kDataLen - 1,
vasilvv9efbb912020-06-05 08:59:26 -0700391 NO_FIN, NOT_RETRANSMISSION,
392 QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500393 }));
renjietangb38e6352019-10-24 09:38:20 -0700394 EXPECT_CALL(*stream_, OnCanWriteNewData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500395 stream_->OnCanWrite();
fayang8265a2a2019-10-16 11:23:51 -0700396 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500397
398 // And finally the end of the bytes_consumed.
renjietang41a1b412020-02-27 15:05:14 -0800399 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500400 .WillOnce(InvokeWithoutArgs([this]() {
renjietang7c239172020-02-21 13:50:39 -0800401 return session_->ConsumeData(stream_->id(), 2u, 2 * kDataLen - 2,
vasilvv9efbb912020-06-05 08:59:26 -0700402 NO_FIN, NOT_RETRANSMISSION,
403 QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500404 }));
renjietangb38e6352019-10-24 09:38:20 -0700405 EXPECT_CALL(*stream_, OnCanWriteNewData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500406 stream_->OnCanWrite();
fayang8265a2a2019-10-16 11:23:51 -0700407 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500408}
409
410TEST_P(QuicStreamTest, WriteOrBufferDataReachStreamLimit) {
411 Initialize();
vasilvvc48c8712019-03-11 13:38:16 -0700412 std::string data("aaaaa");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500413 QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - data.length(),
414 stream_);
renjietang41a1b412020-02-27 15:05:14 -0800415 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800416 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500417 stream_->WriteOrBufferData(data, false, nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700418 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500419 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
420 EXPECT_QUIC_BUG(stream_->WriteOrBufferData("a", false, nullptr),
421 "Write too many data via stream");
422}
423
424TEST_P(QuicStreamTest, ConnectionCloseAfterStreamClose) {
425 Initialize();
426
427 QuicStreamPeer::CloseReadSide(stream_);
428 stream_->CloseWriteSide();
bncf6f82b12019-10-30 07:01:01 -0700429 EXPECT_THAT(stream_->stream_error(), IsQuicStreamNoError());
430 EXPECT_THAT(stream_->connection_error(), IsQuicNoError());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500431 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR,
432 ConnectionCloseSource::FROM_SELF);
bncf6f82b12019-10-30 07:01:01 -0700433 EXPECT_THAT(stream_->stream_error(), IsQuicStreamNoError());
434 EXPECT_THAT(stream_->connection_error(), IsQuicNoError());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500435}
436
437TEST_P(QuicStreamTest, RstAlwaysSentIfNoFinSent) {
438 // For flow control accounting, a stream must send either a FIN or a RST frame
439 // before termination.
440 // Test that if no FIN has been sent, we send a RST.
441
442 Initialize();
443 EXPECT_FALSE(fin_sent());
444 EXPECT_FALSE(rst_sent());
445
446 // Write some data, with no FIN.
renjietang41a1b412020-02-27 15:05:14 -0800447 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500448 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800449 return session_->ConsumeData(stream_->id(), 1u, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -0700450 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500451 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800452 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 1), false,
453 nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700454 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500455 EXPECT_FALSE(fin_sent());
456 EXPECT_FALSE(rst_sent());
457
458 // Now close the stream, and expect that we send a RST.
459 EXPECT_CALL(*session_, SendRstStream(_, _, _));
fayangb8f83442020-06-01 12:09:17 -0700460 stream_->CloseReadSide();
461 stream_->CloseWriteSide();
zhongyi9fa2be32019-09-10 12:39:01 -0700462 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500463 EXPECT_FALSE(fin_sent());
464 EXPECT_TRUE(rst_sent());
465}
466
467TEST_P(QuicStreamTest, RstNotSentIfFinSent) {
468 // For flow control accounting, a stream must send either a FIN or a RST frame
469 // before termination.
470 // Test that if a FIN has been sent, we don't also send a RST.
471
472 Initialize();
473 EXPECT_FALSE(fin_sent());
474 EXPECT_FALSE(rst_sent());
475
476 // Write some data, with FIN.
renjietang41a1b412020-02-27 15:05:14 -0800477 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500478 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800479 return session_->ConsumeData(stream_->id(), 1u, 0u, FIN,
vasilvv9efbb912020-06-05 08:59:26 -0700480 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500481 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800482 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 1), true,
483 nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500484 EXPECT_TRUE(fin_sent());
485 EXPECT_FALSE(rst_sent());
486
487 // Now close the stream, and expect that we do not send a RST.
fayangb8f83442020-06-01 12:09:17 -0700488 stream_->CloseReadSide();
489 stream_->CloseWriteSide();
QUICHE teama6ef0a62019-03-07 20:34:33 -0500490 EXPECT_TRUE(fin_sent());
491 EXPECT_FALSE(rst_sent());
492}
493
494TEST_P(QuicStreamTest, OnlySendOneRst) {
495 // For flow control accounting, a stream must send either a FIN or a RST frame
496 // before termination.
497 // Test that if a stream sends a RST, it doesn't send an additional RST during
498 // OnClose() (this shouldn't be harmful, but we shouldn't do it anyway...)
499
500 Initialize();
501 EXPECT_FALSE(fin_sent());
502 EXPECT_FALSE(rst_sent());
503
504 // Reset the stream.
505 const int expected_resets = 1;
506 EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(expected_resets);
507 stream_->Reset(QUIC_STREAM_CANCELLED);
508 EXPECT_FALSE(fin_sent());
509 EXPECT_TRUE(rst_sent());
510
511 // Now close the stream (any further resets being sent would break the
512 // expectation above).
fayangb8f83442020-06-01 12:09:17 -0700513 stream_->CloseReadSide();
514 stream_->CloseWriteSide();
QUICHE teama6ef0a62019-03-07 20:34:33 -0500515 EXPECT_FALSE(fin_sent());
516 EXPECT_TRUE(rst_sent());
517}
518
519TEST_P(QuicStreamTest, StreamFlowControlMultipleWindowUpdates) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500520 Initialize();
521
522 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we
523 // want to make sure we latch the largest offset we see.
524
525 // Initially should be default.
526 EXPECT_EQ(
renjietang39979d32019-09-13 10:02:13 -0700527 kMinimumFlowControlSendWindow,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500528 QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller()));
529
530 // Check a single WINDOW_UPDATE results in correct offset.
531 QuicWindowUpdateFrame window_update_1(kInvalidControlFrameId, stream_->id(),
renjietang39979d32019-09-13 10:02:13 -0700532 kMinimumFlowControlSendWindow + 5);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500533 stream_->OnWindowUpdateFrame(window_update_1);
renjietangd088eab2019-11-21 14:54:41 -0800534 EXPECT_EQ(window_update_1.max_data, QuicFlowControllerPeer::SendWindowOffset(
535 stream_->flow_controller()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500536
537 // Now send a few more WINDOW_UPDATES and make sure that only the largest is
538 // remembered.
539 QuicWindowUpdateFrame window_update_2(kInvalidControlFrameId, stream_->id(),
540 1);
541 QuicWindowUpdateFrame window_update_3(kInvalidControlFrameId, stream_->id(),
renjietang39979d32019-09-13 10:02:13 -0700542 kMinimumFlowControlSendWindow + 10);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500543 QuicWindowUpdateFrame window_update_4(kInvalidControlFrameId, stream_->id(),
544 5678);
545 stream_->OnWindowUpdateFrame(window_update_2);
546 stream_->OnWindowUpdateFrame(window_update_3);
547 stream_->OnWindowUpdateFrame(window_update_4);
renjietangd088eab2019-11-21 14:54:41 -0800548 EXPECT_EQ(window_update_3.max_data, QuicFlowControllerPeer::SendWindowOffset(
549 stream_->flow_controller()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500550}
551
552TEST_P(QuicStreamTest, FrameStats) {
553 Initialize();
554
555 EXPECT_EQ(0, stream_->num_frames_received());
556 EXPECT_EQ(0, stream_->num_duplicate_frames_received());
renjietangb38e6352019-10-24 09:38:20 -0700557 QuicStreamFrame frame(stream_->id(), false, 0, ".");
558 EXPECT_CALL(*stream_, OnDataAvailable()).Times(2);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500559 stream_->OnStreamFrame(frame);
560 EXPECT_EQ(1, stream_->num_frames_received());
561 EXPECT_EQ(0, stream_->num_duplicate_frames_received());
562 stream_->OnStreamFrame(frame);
563 EXPECT_EQ(2, stream_->num_frames_received());
564 EXPECT_EQ(1, stream_->num_duplicate_frames_received());
renjietangb38e6352019-10-24 09:38:20 -0700565 QuicStreamFrame frame2(stream_->id(), false, 1, "abc");
566 stream_->OnStreamFrame(frame2);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500567}
568
569// Verify that when we receive a packet which violates flow control (i.e. sends
570// too much data on the stream) that the stream sequencer never sees this frame,
571// as we check for violation and close the connection early.
572TEST_P(QuicStreamTest, StreamSequencerNeverSeesPacketsViolatingFlowControl) {
573 Initialize();
574
575 // Receive a stream frame that violates flow control: the byte offset is
576 // higher than the receive window offset.
577 QuicStreamFrame frame(stream_->id(), false,
renjietangb38e6352019-10-24 09:38:20 -0700578 kInitialSessionFlowControlWindowForTest + 1, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500579 EXPECT_GT(frame.offset, QuicFlowControllerPeer::ReceiveWindowOffset(
580 stream_->flow_controller()));
581
582 // Stream should not accept the frame, and the connection should be closed.
583 EXPECT_CALL(*connection_,
584 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _));
585 stream_->OnStreamFrame(frame);
586}
587
588// Verify that after the consumer calls StopReading(), the stream still sends
589// flow control updates.
590TEST_P(QuicStreamTest, StopReadingSendsFlowControl) {
591 Initialize();
592
593 stream_->StopReading();
594
595 // Connection should not get terminated due to flow control errors.
596 EXPECT_CALL(*connection_,
597 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _))
598 .Times(0);
599 EXPECT_CALL(*connection_, SendControlFrame(_))
600 .Times(AtLeast(1))
bnc5b3c3be2019-06-25 10:37:09 -0700601 .WillRepeatedly(Invoke(&ClearControlFrame));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500602
vasilvvc48c8712019-03-11 13:38:16 -0700603 std::string data(1000, 'x');
QUICHE teama6ef0a62019-03-07 20:34:33 -0500604 for (QuicStreamOffset offset = 0;
605 offset < 2 * kInitialStreamFlowControlWindowForTest;
606 offset += data.length()) {
607 QuicStreamFrame frame(stream_->id(), false, offset, data);
608 stream_->OnStreamFrame(frame);
609 }
610 EXPECT_LT(
611 kInitialStreamFlowControlWindowForTest,
612 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
613}
614
615TEST_P(QuicStreamTest, FinalByteOffsetFromFin) {
616 Initialize();
617
renjietang6c066562019-11-04 17:05:59 -0800618 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500619
renjietangb38e6352019-10-24 09:38:20 -0700620 QuicStreamFrame stream_frame_no_fin(stream_->id(), false, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500621 stream_->OnStreamFrame(stream_frame_no_fin);
renjietang6c066562019-11-04 17:05:59 -0800622 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500623
renjietangb38e6352019-10-24 09:38:20 -0700624 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500625 stream_->OnStreamFrame(stream_frame_with_fin);
renjietang6c066562019-11-04 17:05:59 -0800626 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500627}
628
629TEST_P(QuicStreamTest, FinalByteOffsetFromRst) {
630 Initialize();
631
renjietang6c066562019-11-04 17:05:59 -0800632 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500633 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
634 QUIC_STREAM_CANCELLED, 1234);
635 stream_->OnStreamReset(rst_frame);
renjietang6c066562019-11-04 17:05:59 -0800636 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500637}
638
639TEST_P(QuicStreamTest, InvalidFinalByteOffsetFromRst) {
640 Initialize();
641
renjietang6c066562019-11-04 17:05:59 -0800642 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500643 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
644 QUIC_STREAM_CANCELLED, 0xFFFFFFFFFFFF);
645 // Stream should not accept the frame, and the connection should be closed.
646 EXPECT_CALL(*connection_,
647 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _));
648 stream_->OnStreamReset(rst_frame);
renjietang6c066562019-11-04 17:05:59 -0800649 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
fayangb8f83442020-06-01 12:09:17 -0700650 stream_->CloseReadSide();
651 stream_->CloseWriteSide();
QUICHE teama6ef0a62019-03-07 20:34:33 -0500652}
653
654TEST_P(QuicStreamTest, FinalByteOffsetFromZeroLengthStreamFrame) {
655 // When receiving Trailers, an empty stream frame is created with the FIN set,
656 // and is passed to OnStreamFrame. The Trailers may be sent in advance of
657 // queued body bytes being sent, and thus the final byte offset may exceed
658 // current flow control limits. Flow control should only be concerned with
659 // data that has actually been sent/received, so verify that flow control
660 // ignores such a stream frame.
661 Initialize();
662
renjietang6c066562019-11-04 17:05:59 -0800663 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500664 const QuicStreamOffset kByteOffsetExceedingFlowControlWindow =
665 kInitialSessionFlowControlWindowForTest + 1;
666 const QuicStreamOffset current_stream_flow_control_offset =
667 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller());
668 const QuicStreamOffset current_connection_flow_control_offset =
669 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller());
670 ASSERT_GT(kByteOffsetExceedingFlowControlWindow,
671 current_stream_flow_control_offset);
672 ASSERT_GT(kByteOffsetExceedingFlowControlWindow,
673 current_connection_flow_control_offset);
674 QuicStreamFrame zero_length_stream_frame_with_fin(
675 stream_->id(), /*fin=*/true, kByteOffsetExceedingFlowControlWindow,
dmcardlecf0bfcf2019-12-13 08:08:21 -0800676 quiche::QuicheStringPiece());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500677 EXPECT_EQ(0, zero_length_stream_frame_with_fin.data_length);
678
679 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
680 stream_->OnStreamFrame(zero_length_stream_frame_with_fin);
renjietang6c066562019-11-04 17:05:59 -0800681 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500682
683 // The flow control receive offset values should not have changed.
684 EXPECT_EQ(
685 current_stream_flow_control_offset,
686 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
687 EXPECT_EQ(
688 current_connection_flow_control_offset,
689 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller()));
690}
691
692TEST_P(QuicStreamTest, OnStreamResetOffsetOverflow) {
693 Initialize();
694 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
695 QUIC_STREAM_CANCELLED, kMaxStreamLength + 1);
696 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
697 stream_->OnStreamReset(rst_frame);
698}
699
700TEST_P(QuicStreamTest, OnStreamFrameUpperLimit) {
701 Initialize();
702
703 // Modify receive window offset and sequencer buffer total_bytes_read_ to
704 // avoid flow control violation.
705 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
706 kMaxStreamLength + 5u);
707 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
708 kMaxStreamLength + 5u);
709 QuicStreamSequencerPeer::SetFrameBufferTotalBytesRead(
710 QuicStreamPeer::sequencer(stream_), kMaxStreamLength - 10u);
711
712 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _))
713 .Times(0);
renjietangb38e6352019-10-24 09:38:20 -0700714 QuicStreamFrame stream_frame(stream_->id(), false, kMaxStreamLength - 1, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500715 stream_->OnStreamFrame(stream_frame);
renjietangb38e6352019-10-24 09:38:20 -0700716 QuicStreamFrame stream_frame2(stream_->id(), true, kMaxStreamLength, "");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500717 stream_->OnStreamFrame(stream_frame2);
718}
719
720TEST_P(QuicStreamTest, StreamTooLong) {
721 Initialize();
722 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _))
723 .Times(1);
renjietangb38e6352019-10-24 09:38:20 -0700724 QuicStreamFrame stream_frame(stream_->id(), false, kMaxStreamLength, ".");
dmcardlecf0bfcf2019-12-13 08:08:21 -0800725 EXPECT_QUIC_PEER_BUG(
726 stream_->OnStreamFrame(stream_frame),
727 quiche::QuicheStrCat("Receive stream frame on stream ", stream_->id(),
728 " reaches max stream length"));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500729}
730
renjietang9bf25642019-10-10 10:21:15 -0700731TEST_P(QuicStreamTest, SetDrainingIncomingOutgoing) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500732 // Don't have incoming data consumed.
733 Initialize();
734
735 // Incoming data with FIN.
renjietangb38e6352019-10-24 09:38:20 -0700736 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500737 stream_->OnStreamFrame(stream_frame_with_fin);
738 // The FIN has been received but not consumed.
renjietang6c066562019-11-04 17:05:59 -0800739 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500740 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
741 EXPECT_FALSE(stream_->reading_stopped());
742
fayang01591ae2020-04-23 14:14:56 -0700743 EXPECT_EQ(1u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500744
745 // Outgoing data with FIN.
renjietang41a1b412020-02-27 15:05:14 -0800746 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500747 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800748 return session_->ConsumeData(stream_->id(), 2u, 0u, FIN,
vasilvv9efbb912020-06-05 08:59:26 -0700749 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500750 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800751 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true,
752 nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500753 EXPECT_TRUE(stream_->write_side_closed());
754
fayang116fa4c2020-06-02 08:10:49 -0700755 EXPECT_EQ(1u, QuicSessionPeer::GetNumDrainingStreams(session_.get()));
fayang01591ae2020-04-23 14:14:56 -0700756 EXPECT_EQ(0u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500757}
758
renjietang9bf25642019-10-10 10:21:15 -0700759TEST_P(QuicStreamTest, SetDrainingOutgoingIncoming) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500760 // Don't have incoming data consumed.
761 Initialize();
762
763 // Outgoing data with FIN.
renjietang41a1b412020-02-27 15:05:14 -0800764 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500765 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800766 return session_->ConsumeData(stream_->id(), 2u, 0u, FIN,
vasilvv9efbb912020-06-05 08:59:26 -0700767 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500768 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800769 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true,
770 nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500771 EXPECT_TRUE(stream_->write_side_closed());
772
fayang01591ae2020-04-23 14:14:56 -0700773 EXPECT_EQ(1u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500774
775 // Incoming data with FIN.
renjietangb38e6352019-10-24 09:38:20 -0700776 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500777 stream_->OnStreamFrame(stream_frame_with_fin);
778 // The FIN has been received but not consumed.
renjietang6c066562019-11-04 17:05:59 -0800779 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500780 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
781 EXPECT_FALSE(stream_->reading_stopped());
782
fayang116fa4c2020-06-02 08:10:49 -0700783 EXPECT_EQ(1u, QuicSessionPeer::GetNumDrainingStreams(session_.get()));
fayang01591ae2020-04-23 14:14:56 -0700784 EXPECT_EQ(0u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500785}
786
787TEST_P(QuicStreamTest, EarlyResponseFinHandling) {
788 // Verify that if the server completes the response before reading the end of
789 // the request, the received FIN is recorded.
790
791 Initialize();
792 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
renjietang41a1b412020-02-27 15:05:14 -0800793 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800794 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500795
796 // Receive data for the request.
renjietangb38e6352019-10-24 09:38:20 -0700797 EXPECT_CALL(*stream_, OnDataAvailable()).Times(1);
798 QuicStreamFrame frame1(stream_->id(), false, 0, "Start");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500799 stream_->OnStreamFrame(frame1);
800 // When QuicSimpleServerStream sends the response, it calls
801 // QuicStream::CloseReadSide() first.
802 QuicStreamPeer::CloseReadSide(stream_);
803 // Send data and FIN for the response.
804 stream_->WriteOrBufferData(kData1, false, nullptr);
805 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
806 // Receive remaining data and FIN for the request.
renjietangb38e6352019-10-24 09:38:20 -0700807 QuicStreamFrame frame2(stream_->id(), true, 0, "End");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500808 stream_->OnStreamFrame(frame2);
809 EXPECT_TRUE(stream_->fin_received());
renjietang6c066562019-11-04 17:05:59 -0800810 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500811}
812
813TEST_P(QuicStreamTest, StreamWaitsForAcks) {
814 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800815 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800816 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500817 // Stream is not waiting for acks initially.
818 EXPECT_FALSE(stream_->IsWaitingForAcks());
819 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
zhongyi9fa2be32019-09-10 12:39:01 -0700820 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500821
822 // Send kData1.
823 stream_->WriteOrBufferData(kData1, false, nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700824 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500825 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
826 EXPECT_TRUE(stream_->IsWaitingForAcks());
827 QuicByteCount newly_acked_length = 0;
828 EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800829 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500830 &newly_acked_length));
831 EXPECT_EQ(9u, newly_acked_length);
832 // Stream is not waiting for acks as all sent data is acked.
833 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700834 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500835 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
836
837 // Send kData2.
838 stream_->WriteOrBufferData(kData2, false, nullptr);
839 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700840 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500841 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
842 // Send FIN.
843 stream_->WriteOrBufferData("", true, nullptr);
844 // Fin only frame is not stored in send buffer.
845 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
846
847 // kData2 is retransmitted.
848 stream_->OnStreamFrameRetransmitted(9, 9, false);
849
850 // kData2 is acked.
851 EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800852 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500853 &newly_acked_length));
854 EXPECT_EQ(9u, newly_acked_length);
855 // Stream is waiting for acks as FIN is not acked.
856 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700857 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500858 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
859
860 // FIN is acked.
861 EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 0, true, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800862 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500863 &newly_acked_length));
864 EXPECT_EQ(0u, newly_acked_length);
865 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700866 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500867 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
868}
869
870TEST_P(QuicStreamTest, StreamDataGetAckedOutOfOrder) {
871 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800872 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800873 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500874 // Send data.
875 stream_->WriteOrBufferData(kData1, false, nullptr);
876 stream_->WriteOrBufferData(kData1, false, nullptr);
877 stream_->WriteOrBufferData(kData1, false, nullptr);
878 stream_->WriteOrBufferData("", true, nullptr);
879 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
880 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700881 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500882 QuicByteCount newly_acked_length = 0;
883 EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800884 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500885 &newly_acked_length));
fayang8265a2a2019-10-16 11:23:51 -0700886 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500887 EXPECT_EQ(9u, newly_acked_length);
888 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
889 EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800890 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500891 &newly_acked_length));
fayang8265a2a2019-10-16 11:23:51 -0700892 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500893 EXPECT_EQ(9u, newly_acked_length);
894 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
895 EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800896 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500897 &newly_acked_length));
fayang8265a2a2019-10-16 11:23:51 -0700898 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500899 EXPECT_EQ(9u, newly_acked_length);
900 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
901 // FIN is not acked yet.
902 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700903 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500904 EXPECT_TRUE(stream_->OnStreamFrameAcked(27, 0, true, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800905 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500906 &newly_acked_length));
907 EXPECT_EQ(0u, newly_acked_length);
908 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700909 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500910}
911
912TEST_P(QuicStreamTest, CancelStream) {
913 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800914 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800915 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500916 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700917 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500918 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
919
920 stream_->WriteOrBufferData(kData1, false, nullptr);
921 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700922 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500923 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
924 // Cancel stream.
925 stream_->Reset(QUIC_STREAM_NO_ERROR);
926 // stream still waits for acks as the error code is QUIC_STREAM_NO_ERROR, and
927 // data is going to be retransmitted.
928 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700929 EXPECT_TRUE(session_->HasUnackedStreamData());
zhongyi1b2f7832019-06-14 13:31:34 -0700930 EXPECT_CALL(*connection_,
931 OnStreamReset(stream_->id(), QUIC_STREAM_CANCELLED));
renjietangeab92852019-10-25 12:16:14 -0700932 EXPECT_CALL(*connection_, SendControlFrame(_))
933 .Times(AtLeast(1))
934 .WillRepeatedly(Invoke(&ClearControlFrame));
zhongyi1b2f7832019-06-14 13:31:34 -0700935 EXPECT_CALL(*session_, SendRstStream(stream_->id(), QUIC_STREAM_CANCELLED, 9))
936 .WillOnce(InvokeWithoutArgs([this]() {
renjietang61cc2452019-11-26 10:57:10 -0800937 session_->ReallySendRstStream(stream_->id(), QUIC_STREAM_CANCELLED,
938 stream_->stream_bytes_written());
zhongyi1b2f7832019-06-14 13:31:34 -0700939 }));
940
QUICHE teama6ef0a62019-03-07 20:34:33 -0500941 stream_->Reset(QUIC_STREAM_CANCELLED);
942 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
943 // Stream stops waiting for acks as data is not going to be retransmitted.
944 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700945 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500946}
947
948TEST_P(QuicStreamTest, RstFrameReceivedStreamNotFinishSending) {
renjietang9bf25642019-10-10 10:21:15 -0700949 if (VersionHasIetfQuicFrames(GetParam().transport_version)) {
950 // In IETF QUIC, receiving a RESET_STREAM will only close the read side. The
951 // stream itself is not closed and will not send reset.
952 return;
953 }
954
QUICHE teama6ef0a62019-03-07 20:34:33 -0500955 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800956 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800957 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500958 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700959 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500960 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
961
962 stream_->WriteOrBufferData(kData1, false, nullptr);
963 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700964 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500965 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
966
967 // RST_STREAM received.
968 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
969 QUIC_STREAM_CANCELLED, 9);
970 EXPECT_CALL(*session_,
971 SendRstStream(stream_->id(), QUIC_RST_ACKNOWLEDGEMENT, 9));
972 stream_->OnStreamReset(rst_frame);
973 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
974 // Stream stops waiting for acks as it does not finish sending and rst is
975 // sent.
976 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700977 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500978}
979
980TEST_P(QuicStreamTest, RstFrameReceivedStreamFinishSending) {
981 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800982 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800983 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500984 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700985 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500986 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
987
988 stream_->WriteOrBufferData(kData1, true, nullptr);
989 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700990 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500991
992 // RST_STREAM received.
993 EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(0);
994 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
995 QUIC_STREAM_CANCELLED, 1234);
996 stream_->OnStreamReset(rst_frame);
997 // Stream still waits for acks as it finishes sending and has unacked data.
998 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700999 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001000 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1001}
1002
1003TEST_P(QuicStreamTest, ConnectionClosed) {
1004 Initialize();
renjietang41a1b412020-02-27 15:05:14 -08001005 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001006 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001007 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001008 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001009 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1010
1011 stream_->WriteOrBufferData(kData1, false, nullptr);
1012 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001013 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001014 EXPECT_CALL(*session_,
1015 SendRstStream(stream_->id(), QUIC_RST_ACKNOWLEDGEMENT, 9));
1016 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR,
1017 ConnectionCloseSource::FROM_SELF);
1018 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1019 // Stream stops waiting for acks as connection is going to close.
1020 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001021 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001022}
1023
1024TEST_P(QuicStreamTest, CanWriteNewDataAfterData) {
wub49855982019-05-01 14:16:26 -07001025 SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001026 Initialize();
1027 EXPECT_TRUE(stream_->CanWriteNewDataAfterData(99));
1028 EXPECT_FALSE(stream_->CanWriteNewDataAfterData(100));
1029}
1030
1031TEST_P(QuicStreamTest, WriteBufferedData) {
1032 // Set buffered data low water mark to be 100.
wub49855982019-05-01 14:16:26 -07001033 SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001034
1035 Initialize();
vasilvvc48c8712019-03-11 13:38:16 -07001036 std::string data(1024, 'a');
QUICHE teama6ef0a62019-03-07 20:34:33 -05001037 EXPECT_TRUE(stream_->CanWriteNewData());
1038
1039 // Testing WriteOrBufferData.
renjietang41a1b412020-02-27 15:05:14 -08001040 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001041 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001042 return session_->ConsumeData(stream_->id(), 100u, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001043 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001044 }));
1045 stream_->WriteOrBufferData(data, false, nullptr);
1046 stream_->WriteOrBufferData(data, false, nullptr);
1047 stream_->WriteOrBufferData(data, false, nullptr);
zhongyi1b2f7832019-06-14 13:31:34 -07001048 EXPECT_TRUE(stream_->IsWaitingForAcks());
1049
QUICHE teama6ef0a62019-03-07 20:34:33 -05001050 // Verify all data is saved.
1051 EXPECT_EQ(3 * data.length() - 100, stream_->BufferedDataBytes());
1052
renjietang41a1b412020-02-27 15:05:14 -08001053 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001054 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001055 return session_->ConsumeData(stream_->id(), 100, 100u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001056 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001057 }));
1058 // Buffered data size > threshold, do not ask upper layer for more data.
1059 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(0);
1060 stream_->OnCanWrite();
1061 EXPECT_EQ(3 * data.length() - 200, stream_->BufferedDataBytes());
1062 EXPECT_FALSE(stream_->CanWriteNewData());
1063
1064 // Send buffered data to make buffered data size < threshold.
dschinazif1e7b422020-04-30 12:21:28 -07001065 QuicByteCount data_to_write =
1066 3 * data.length() - 200 -
1067 GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1;
renjietang41a1b412020-02-27 15:05:14 -08001068 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001069 .WillOnce(InvokeWithoutArgs([this, data_to_write]() {
renjietang7c239172020-02-21 13:50:39 -08001070 return session_->ConsumeData(stream_->id(), data_to_write, 200u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001071 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001072 }));
1073 // Buffered data size < threshold, ask upper layer for more data.
1074 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1075 stream_->OnCanWrite();
dschinazi696ee602019-04-25 16:05:35 -07001076 EXPECT_EQ(static_cast<uint64_t>(
1077 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001078 stream_->BufferedDataBytes());
1079 EXPECT_TRUE(stream_->CanWriteNewData());
1080
1081 // Flush all buffered data.
renjietang41a1b412020-02-27 15:05:14 -08001082 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001083 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001084 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1085 stream_->OnCanWrite();
1086 EXPECT_EQ(0u, stream_->BufferedDataBytes());
1087 EXPECT_FALSE(stream_->HasBufferedData());
1088 EXPECT_TRUE(stream_->CanWriteNewData());
1089
1090 // Testing Writev.
renjietang41a1b412020-02-27 15:05:14 -08001091 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001092 .WillOnce(Return(QuicConsumedData(0, false)));
1093 struct iovec iov = {const_cast<char*>(data.data()), data.length()};
1094 QuicMemSliceStorage storage(
1095 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1096 1024);
1097 QuicConsumedData consumed = stream_->WriteMemSlices(storage.ToSpan(), false);
1098
1099 // There is no buffered data before, all data should be consumed without
1100 // respecting buffered data upper limit.
1101 EXPECT_EQ(data.length(), consumed.bytes_consumed);
1102 EXPECT_FALSE(consumed.fin_consumed);
1103 EXPECT_EQ(data.length(), stream_->BufferedDataBytes());
1104 EXPECT_FALSE(stream_->CanWriteNewData());
1105
renjietang41a1b412020-02-27 15:05:14 -08001106 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001107 QuicMemSliceStorage storage2(
1108 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1109 1024);
1110 consumed = stream_->WriteMemSlices(storage2.ToSpan(), false);
1111 // No Data can be consumed as buffered data is beyond upper limit.
1112 EXPECT_EQ(0u, consumed.bytes_consumed);
1113 EXPECT_FALSE(consumed.fin_consumed);
1114 EXPECT_EQ(data.length(), stream_->BufferedDataBytes());
1115
1116 data_to_write =
1117 data.length() - GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1;
renjietang41a1b412020-02-27 15:05:14 -08001118 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001119 .WillOnce(InvokeWithoutArgs([this, data_to_write]() {
renjietang7c239172020-02-21 13:50:39 -08001120 return session_->ConsumeData(stream_->id(), data_to_write, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001121 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001122 }));
1123
1124 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1125 stream_->OnCanWrite();
dschinazi696ee602019-04-25 16:05:35 -07001126 EXPECT_EQ(static_cast<uint64_t>(
1127 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001128 stream_->BufferedDataBytes());
1129 EXPECT_TRUE(stream_->CanWriteNewData());
1130
renjietang41a1b412020-02-27 15:05:14 -08001131 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001132 // All data can be consumed as buffered data is below upper limit.
1133 QuicMemSliceStorage storage3(
1134 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1135 1024);
1136 consumed = stream_->WriteMemSlices(storage3.ToSpan(), false);
1137 EXPECT_EQ(data.length(), consumed.bytes_consumed);
1138 EXPECT_FALSE(consumed.fin_consumed);
1139 EXPECT_EQ(data.length() + GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1,
1140 stream_->BufferedDataBytes());
1141 EXPECT_FALSE(stream_->CanWriteNewData());
1142}
1143
1144TEST_P(QuicStreamTest, WritevDataReachStreamLimit) {
1145 Initialize();
vasilvvc48c8712019-03-11 13:38:16 -07001146 std::string data("aaaaa");
QUICHE teama6ef0a62019-03-07 20:34:33 -05001147 QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - data.length(),
1148 stream_);
renjietang41a1b412020-02-27 15:05:14 -08001149 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001150 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001151 struct iovec iov = {const_cast<char*>(data.data()), 5u};
1152 QuicMemSliceStorage storage(
1153 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1154 1024);
1155 QuicConsumedData consumed = stream_->WriteMemSlices(storage.ToSpan(), false);
1156 EXPECT_EQ(data.length(), consumed.bytes_consumed);
1157 struct iovec iov2 = {const_cast<char*>(data.data()), 1u};
1158 QuicMemSliceStorage storage2(
1159 &iov2, 1,
1160 session_->connection()->helper()->GetStreamSendBufferAllocator(), 1024);
1161 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
1162 EXPECT_QUIC_BUG(stream_->WriteMemSlices(storage2.ToSpan(), false),
1163 "Write too many data via stream");
1164}
1165
1166TEST_P(QuicStreamTest, WriteMemSlices) {
1167 // Set buffered data low water mark to be 100.
wub49855982019-05-01 14:16:26 -07001168 SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001169
1170 Initialize();
1171 char data[1024];
nharper6b7aa8b2020-04-30 17:23:35 -07001172 std::vector<std::pair<char*, size_t>> buffers;
bnc4e9283d2019-12-17 07:08:57 -08001173 buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data)));
1174 buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data)));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001175 QuicTestMemSliceVector vector1(buffers);
1176 QuicTestMemSliceVector vector2(buffers);
1177 QuicMemSliceSpan span1 = vector1.span();
1178 QuicMemSliceSpan span2 = vector2.span();
1179
renjietang41a1b412020-02-27 15:05:14 -08001180 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001181 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001182 return session_->ConsumeData(stream_->id(), 100u, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001183 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001184 }));
1185 // There is no buffered data before, all data should be consumed.
1186 QuicConsumedData consumed = stream_->WriteMemSlices(span1, false);
1187 EXPECT_EQ(2048u, consumed.bytes_consumed);
1188 EXPECT_FALSE(consumed.fin_consumed);
bnc4e9283d2019-12-17 07:08:57 -08001189 EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) - 100, stream_->BufferedDataBytes());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001190 EXPECT_FALSE(stream_->fin_buffered());
1191
renjietang41a1b412020-02-27 15:05:14 -08001192 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001193 // No Data can be consumed as buffered data is beyond upper limit.
1194 consumed = stream_->WriteMemSlices(span2, true);
1195 EXPECT_EQ(0u, consumed.bytes_consumed);
1196 EXPECT_FALSE(consumed.fin_consumed);
bnc4e9283d2019-12-17 07:08:57 -08001197 EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) - 100, stream_->BufferedDataBytes());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001198 EXPECT_FALSE(stream_->fin_buffered());
1199
dschinazif1e7b422020-04-30 12:21:28 -07001200 QuicByteCount data_to_write =
1201 2 * QUICHE_ARRAYSIZE(data) - 100 -
1202 GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1;
renjietang41a1b412020-02-27 15:05:14 -08001203 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001204 .WillOnce(InvokeWithoutArgs([this, data_to_write]() {
renjietang7c239172020-02-21 13:50:39 -08001205 return session_->ConsumeData(stream_->id(), data_to_write, 100u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001206 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001207 }));
1208 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1209 stream_->OnCanWrite();
dschinazi696ee602019-04-25 16:05:35 -07001210 EXPECT_EQ(static_cast<uint64_t>(
1211 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001212 stream_->BufferedDataBytes());
1213 // Try to write slices2 again.
renjietang41a1b412020-02-27 15:05:14 -08001214 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001215 consumed = stream_->WriteMemSlices(span2, true);
1216 EXPECT_EQ(2048u, consumed.bytes_consumed);
1217 EXPECT_TRUE(consumed.fin_consumed);
bnc4e9283d2019-12-17 07:08:57 -08001218 EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) +
QUICHE teama6ef0a62019-03-07 20:34:33 -05001219 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1,
1220 stream_->BufferedDataBytes());
1221 EXPECT_TRUE(stream_->fin_buffered());
1222
1223 // Flush all buffered data.
renjietang41a1b412020-02-27 15:05:14 -08001224 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001225 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001226 stream_->OnCanWrite();
1227 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(0);
1228 EXPECT_FALSE(stream_->HasBufferedData());
1229 EXPECT_TRUE(stream_->write_side_closed());
1230}
1231
1232TEST_P(QuicStreamTest, WriteMemSlicesReachStreamLimit) {
1233 Initialize();
1234 QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - 5u, stream_);
1235 char data[5];
nharper6b7aa8b2020-04-30 17:23:35 -07001236 std::vector<std::pair<char*, size_t>> buffers;
bnc4e9283d2019-12-17 07:08:57 -08001237 buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data)));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001238 QuicTestMemSliceVector vector1(buffers);
1239 QuicMemSliceSpan span1 = vector1.span();
renjietang41a1b412020-02-27 15:05:14 -08001240 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001241 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001242 return session_->ConsumeData(stream_->id(), 5u, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001243 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001244 }));
1245 // There is no buffered data before, all data should be consumed.
1246 QuicConsumedData consumed = stream_->WriteMemSlices(span1, false);
1247 EXPECT_EQ(5u, consumed.bytes_consumed);
1248
nharper6b7aa8b2020-04-30 17:23:35 -07001249 std::vector<std::pair<char*, size_t>> buffers2;
QUICHE teama6ef0a62019-03-07 20:34:33 -05001250 buffers2.push_back(std::make_pair(data, 1u));
1251 QuicTestMemSliceVector vector2(buffers);
1252 QuicMemSliceSpan span2 = vector2.span();
1253 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
1254 EXPECT_QUIC_BUG(stream_->WriteMemSlices(span2, false),
1255 "Write too many data via stream");
1256}
1257
1258TEST_P(QuicStreamTest, StreamDataGetAckedMultipleTimes) {
1259 Initialize();
renjietang41a1b412020-02-27 15:05:14 -08001260 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001261 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
zhongyi1b2f7832019-06-14 13:31:34 -07001262 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001263 EXPECT_FALSE(session_->HasUnackedStreamData());
zhongyi1b2f7832019-06-14 13:31:34 -07001264
QUICHE teama6ef0a62019-03-07 20:34:33 -05001265 // Send [0, 27) and fin.
1266 stream_->WriteOrBufferData(kData1, false, nullptr);
1267 stream_->WriteOrBufferData(kData1, false, nullptr);
1268 stream_->WriteOrBufferData(kData1, true, nullptr);
1269 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
1270 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001271 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001272 // Ack [0, 9), [5, 22) and [18, 26)
1273 // Verify [0, 9) 9 bytes are acked.
1274 QuicByteCount newly_acked_length = 0;
1275 EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001276 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001277 &newly_acked_length));
1278 EXPECT_EQ(9u, newly_acked_length);
1279 EXPECT_EQ(2u, QuicStreamPeer::SendBuffer(stream_).size());
1280 // Verify [9, 22) 13 bytes are acked.
1281 EXPECT_TRUE(stream_->OnStreamFrameAcked(5, 17, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001282 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001283 &newly_acked_length));
1284 EXPECT_EQ(13u, newly_acked_length);
1285 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1286 // Verify [22, 26) 4 bytes are acked.
1287 EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 8, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001288 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001289 &newly_acked_length));
1290 EXPECT_EQ(4u, newly_acked_length);
1291 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1292 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001293 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001294
1295 // Ack [0, 27). Verify [26, 27) 1 byte is acked.
1296 EXPECT_TRUE(stream_->OnStreamFrameAcked(26, 1, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001297 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001298 &newly_acked_length));
1299 EXPECT_EQ(1u, newly_acked_length);
1300 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1301 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001302 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001303
1304 // Ack Fin.
1305 EXPECT_TRUE(stream_->OnStreamFrameAcked(27, 0, true, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001306 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001307 &newly_acked_length));
1308 EXPECT_EQ(0u, newly_acked_length);
1309 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1310 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001311 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001312
1313 // Ack [10, 27) and fin. No new data is acked.
QUICHE team2f5f30b2020-02-18 08:52:28 -08001314 EXPECT_FALSE(
1315 stream_->OnStreamFrameAcked(10, 17, true, QuicTime::Delta::Zero(),
1316 QuicTime::Zero(), &newly_acked_length));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001317 EXPECT_EQ(0u, newly_acked_length);
1318 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1319 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001320 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001321}
1322
1323TEST_P(QuicStreamTest, OnStreamFrameLost) {
1324 Initialize();
1325
1326 // Send [0, 9).
renjietang41a1b412020-02-27 15:05:14 -08001327 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001328 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001329 stream_->WriteOrBufferData(kData1, false, nullptr);
1330 EXPECT_FALSE(stream_->HasBufferedData());
1331 EXPECT_TRUE(stream_->IsStreamFrameOutstanding(0, 9, false));
1332
1333 // Try to send [9, 27), but connection is blocked.
renjietang41a1b412020-02-27 15:05:14 -08001334 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001335 .WillOnce(Return(QuicConsumedData(0, false)));
1336 stream_->WriteOrBufferData(kData2, false, nullptr);
1337 stream_->WriteOrBufferData(kData2, false, nullptr);
1338 EXPECT_TRUE(stream_->HasBufferedData());
1339 EXPECT_FALSE(stream_->HasPendingRetransmission());
1340
1341 // Lost [0, 9). When stream gets a chance to write, only lost data is
1342 // transmitted.
1343 stream_->OnStreamFrameLost(0, 9, false);
1344 EXPECT_TRUE(stream_->HasPendingRetransmission());
renjietang41a1b412020-02-27 15:05:14 -08001345 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001346 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietangb38e6352019-10-24 09:38:20 -07001347 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001348 stream_->OnCanWrite();
1349 EXPECT_FALSE(stream_->HasPendingRetransmission());
1350 EXPECT_TRUE(stream_->HasBufferedData());
1351
1352 // This OnCanWrite causes [9, 27) to be sent.
renjietang41a1b412020-02-27 15:05:14 -08001353 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001354 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001355 stream_->OnCanWrite();
1356 EXPECT_FALSE(stream_->HasBufferedData());
1357
1358 // Send a fin only frame.
renjietang41a1b412020-02-27 15:05:14 -08001359 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001360 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001361 stream_->WriteOrBufferData("", true, nullptr);
1362
1363 // Lost [9, 27) and fin.
1364 stream_->OnStreamFrameLost(9, 18, false);
1365 stream_->OnStreamFrameLost(27, 0, true);
1366 EXPECT_TRUE(stream_->HasPendingRetransmission());
1367
1368 // Ack [9, 18).
1369 QuicByteCount newly_acked_length = 0;
1370 EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001371 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001372 &newly_acked_length));
1373 EXPECT_EQ(9u, newly_acked_length);
1374 EXPECT_FALSE(stream_->IsStreamFrameOutstanding(9, 3, false));
1375 EXPECT_TRUE(stream_->HasPendingRetransmission());
1376 // This OnCanWrite causes [18, 27) and fin to be retransmitted. Verify fin can
1377 // be bundled with data.
renjietang41a1b412020-02-27 15:05:14 -08001378 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001379 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001380 return session_->ConsumeData(stream_->id(), 9u, 18u, FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001381 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001382 }));
1383 stream_->OnCanWrite();
1384 EXPECT_FALSE(stream_->HasPendingRetransmission());
1385 // Lost [9, 18) again, but it is not considered as lost because kData2
1386 // has been acked.
1387 stream_->OnStreamFrameLost(9, 9, false);
1388 EXPECT_FALSE(stream_->HasPendingRetransmission());
1389 EXPECT_TRUE(stream_->IsStreamFrameOutstanding(27, 0, true));
1390}
1391
1392TEST_P(QuicStreamTest, CannotBundleLostFin) {
1393 Initialize();
1394
1395 // Send [0, 18) and fin.
renjietang41a1b412020-02-27 15:05:14 -08001396 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001397 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001398 stream_->WriteOrBufferData(kData1, false, nullptr);
1399 stream_->WriteOrBufferData(kData2, true, nullptr);
1400
1401 // Lost [0, 9) and fin.
1402 stream_->OnStreamFrameLost(0, 9, false);
1403 stream_->OnStreamFrameLost(18, 0, true);
1404
1405 // Retransmit lost data. Verify [0, 9) and fin are retransmitted in two
1406 // frames.
1407 InSequence s;
renjietang41a1b412020-02-27 15:05:14 -08001408 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001409 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001410 return session_->ConsumeData(stream_->id(), 9u, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001411 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001412 }));
renjietang41a1b412020-02-27 15:05:14 -08001413 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001414 .WillOnce(Return(QuicConsumedData(0, true)));
1415 stream_->OnCanWrite();
1416}
1417
1418TEST_P(QuicStreamTest, MarkConnectionLevelWriteBlockedOnWindowUpdateFrame) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001419 Initialize();
1420
renjietang39979d32019-09-13 10:02:13 -07001421 // Set the config to a small value so that a newly created stream has small
1422 // send flow control window.
1423 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_->config(),
1424 100);
renjietang9bf25642019-10-10 10:21:15 -07001425 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional(
1426 session_->config(), 100);
renjietang39979d32019-09-13 10:02:13 -07001427 auto stream = new TestStream(GetNthClientInitiatedBidirectionalStreamId(
1428 GetParam().transport_version, 2),
1429 session_.get(), BIDIRECTIONAL);
1430 session_->ActivateStream(QuicWrapUnique(stream));
1431
renjietang41a1b412020-02-27 15:05:14 -08001432 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001433 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001434 EXPECT_CALL(*connection_, SendControlFrame(_))
bnc5b3c3be2019-06-25 10:37:09 -07001435 .WillOnce(Invoke(&ClearControlFrame));
vasilvvc48c8712019-03-11 13:38:16 -07001436 std::string data(1024, '.');
renjietang39979d32019-09-13 10:02:13 -07001437 stream->WriteOrBufferData(data, false, nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001438 EXPECT_FALSE(HasWriteBlockedStreams());
1439
1440 QuicWindowUpdateFrame window_update(kInvalidControlFrameId, stream_->id(),
1441 1234);
1442
renjietang39979d32019-09-13 10:02:13 -07001443 stream->OnWindowUpdateFrame(window_update);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001444 // Verify stream is marked connection level write blocked.
1445 EXPECT_TRUE(HasWriteBlockedStreams());
renjietang39979d32019-09-13 10:02:13 -07001446 EXPECT_TRUE(stream->HasBufferedData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001447}
1448
1449// Regression test for b/73282665.
1450TEST_P(QuicStreamTest,
1451 MarkConnectionLevelWriteBlockedOnWindowUpdateFrameWithNoBufferedData) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001452 Initialize();
1453
renjietang39979d32019-09-13 10:02:13 -07001454 // Set the config to a small value so that a newly created stream has small
1455 // send flow control window.
1456 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_->config(),
1457 100);
renjietang9bf25642019-10-10 10:21:15 -07001458 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional(
1459 session_->config(), 100);
renjietang39979d32019-09-13 10:02:13 -07001460 auto stream = new TestStream(GetNthClientInitiatedBidirectionalStreamId(
1461 GetParam().transport_version, 2),
1462 session_.get(), BIDIRECTIONAL);
1463 session_->ActivateStream(QuicWrapUnique(stream));
1464
1465 std::string data(100, '.');
renjietang41a1b412020-02-27 15:05:14 -08001466 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001467 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001468 EXPECT_CALL(*connection_, SendControlFrame(_))
bnc5b3c3be2019-06-25 10:37:09 -07001469 .WillOnce(Invoke(&ClearControlFrame));
renjietang39979d32019-09-13 10:02:13 -07001470 stream->WriteOrBufferData(data, false, nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001471 EXPECT_FALSE(HasWriteBlockedStreams());
1472
1473 QuicWindowUpdateFrame window_update(kInvalidControlFrameId, stream_->id(),
1474 120);
renjietang39979d32019-09-13 10:02:13 -07001475 stream->OnWindowUpdateFrame(window_update);
1476 EXPECT_FALSE(stream->HasBufferedData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001477 // Verify stream is marked as blocked although there is no buffered data.
1478 EXPECT_TRUE(HasWriteBlockedStreams());
1479}
1480
1481TEST_P(QuicStreamTest, RetransmitStreamData) {
1482 Initialize();
1483 InSequence s;
1484
1485 // Send [0, 18) with fin.
renjietang41a1b412020-02-27 15:05:14 -08001486 EXPECT_CALL(*session_, WritevData(stream_->id(), _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001487 .Times(2)
renjietang7c239172020-02-21 13:50:39 -08001488 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001489 stream_->WriteOrBufferData(kData1, false, nullptr);
1490 stream_->WriteOrBufferData(kData1, true, nullptr);
1491 // Ack [10, 13).
1492 QuicByteCount newly_acked_length = 0;
1493 stream_->OnStreamFrameAcked(10, 3, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001494 QuicTime::Zero(), &newly_acked_length);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001495 EXPECT_EQ(3u, newly_acked_length);
1496 // Retransmit [0, 18) with fin, and only [0, 8) is consumed.
renjietang41a1b412020-02-27 15:05:14 -08001497 EXPECT_CALL(*session_, WritevData(stream_->id(), 10, 0, NO_FIN, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001498 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001499 return session_->ConsumeData(stream_->id(), 8, 0u, NO_FIN,
vasilvv9efbb912020-06-05 08:59:26 -07001500 NOT_RETRANSMISSION, QUICHE_NULLOPT);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001501 }));
renjietang4d992bf2020-03-03 13:01:55 -08001502 EXPECT_FALSE(stream_->RetransmitStreamData(0, 18, true, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001503
1504 // Retransmit [0, 18) with fin, and all is consumed.
renjietang41a1b412020-02-27 15:05:14 -08001505 EXPECT_CALL(*session_, WritevData(stream_->id(), 10, 0, NO_FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001506 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang41a1b412020-02-27 15:05:14 -08001507 EXPECT_CALL(*session_, WritevData(stream_->id(), 5, 13, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001508 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang4d992bf2020-03-03 13:01:55 -08001509 EXPECT_TRUE(stream_->RetransmitStreamData(0, 18, true, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001510
1511 // Retransmit [0, 8) with fin, and all is consumed.
renjietang41a1b412020-02-27 15:05:14 -08001512 EXPECT_CALL(*session_, WritevData(stream_->id(), 8, 0, NO_FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001513 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang41a1b412020-02-27 15:05:14 -08001514 EXPECT_CALL(*session_, WritevData(stream_->id(), 0, 18, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001515 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang4d992bf2020-03-03 13:01:55 -08001516 EXPECT_TRUE(stream_->RetransmitStreamData(0, 8, true, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001517}
1518
1519TEST_P(QuicStreamTest, ResetStreamOnTtlExpiresRetransmitLostData) {
1520 Initialize();
1521
renjietang41a1b412020-02-27 15:05:14 -08001522 EXPECT_CALL(*session_, WritevData(stream_->id(), 200, 0, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001523 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
vasilvvc48c8712019-03-11 13:38:16 -07001524 std::string body(200, 'a');
QUICHE teama6ef0a62019-03-07 20:34:33 -05001525 stream_->WriteOrBufferData(body, true, nullptr);
1526
1527 // Set TTL to be 1 s.
1528 QuicTime::Delta ttl = QuicTime::Delta::FromSeconds(1);
1529 ASSERT_TRUE(stream_->MaybeSetTtl(ttl));
1530 // Verify data gets retransmitted because TTL does not expire.
renjietang41a1b412020-02-27 15:05:14 -08001531 EXPECT_CALL(*session_, WritevData(stream_->id(), 100, 0, NO_FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001532 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang4d992bf2020-03-03 13:01:55 -08001533 EXPECT_TRUE(stream_->RetransmitStreamData(0, 100, false, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001534 stream_->OnStreamFrameLost(100, 100, true);
1535 EXPECT_TRUE(stream_->HasPendingRetransmission());
1536
1537 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
1538 // Verify stream gets reset because TTL expires.
1539 EXPECT_CALL(*session_, SendRstStream(_, QUIC_STREAM_TTL_EXPIRED, _)).Times(1);
1540 stream_->OnCanWrite();
1541}
1542
1543TEST_P(QuicStreamTest, ResetStreamOnTtlExpiresEarlyRetransmitData) {
1544 Initialize();
1545
renjietang41a1b412020-02-27 15:05:14 -08001546 EXPECT_CALL(*session_, WritevData(stream_->id(), 200, 0, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001547 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
vasilvvc48c8712019-03-11 13:38:16 -07001548 std::string body(200, 'a');
QUICHE teama6ef0a62019-03-07 20:34:33 -05001549 stream_->WriteOrBufferData(body, true, nullptr);
1550
1551 // Set TTL to be 1 s.
1552 QuicTime::Delta ttl = QuicTime::Delta::FromSeconds(1);
1553 ASSERT_TRUE(stream_->MaybeSetTtl(ttl));
1554
1555 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
1556 // Verify stream gets reset because TTL expires.
1557 EXPECT_CALL(*session_, SendRstStream(_, QUIC_STREAM_TTL_EXPIRED, _)).Times(1);
renjietang4d992bf2020-03-03 13:01:55 -08001558 stream_->RetransmitStreamData(0, 100, false, PTO_RETRANSMISSION);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001559}
1560
1561// Test that QuicStream::StopSending A) is a no-op if the connection is not in
1562// version 99, B) that it properly invokes QuicSession::StopSending, and C) that
1563// the correct data is passed along, including getting the stream ID.
renjietang9bf25642019-10-10 10:21:15 -07001564TEST_P(QuicStreamTest, CheckStopSending) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001565 Initialize();
1566 const int kStopSendingCode = 123;
1567 // These must start as false.
bncc7d9e0c2019-04-16 10:22:15 -07001568 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001569 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
1570 // Expect to actually see a stop sending if and only if we are in version 99.
fkastenholz305e1732019-06-18 05:01:22 -07001571 if (VersionHasIetfQuicFrames(connection_->transport_version())) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001572 EXPECT_CALL(*session_, SendStopSending(kStopSendingCode, stream_->id()))
1573 .Times(1);
1574 } else {
1575 EXPECT_CALL(*session_, SendStopSending(_, _)).Times(0);
1576 }
1577 stream_->SendStopSending(kStopSendingCode);
1578 // Sending a STOP_SENDING does not actually close the local stream.
1579 // Our implementation waits for the responding RESET_STREAM to effect the
1580 // closes. Therefore, read- and write-side closes should both be false.
bncc7d9e0c2019-04-16 10:22:15 -07001581 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001582 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
1583}
1584
1585// Test that OnStreamReset does one-way (read) closes if version 99, two way
1586// (read and write) if not version 99.
1587TEST_P(QuicStreamTest, OnStreamResetReadOrReadWrite) {
1588 Initialize();
bncc7d9e0c2019-04-16 10:22:15 -07001589 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001590 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
1591
1592 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
1593 QUIC_STREAM_CANCELLED, 1234);
1594 stream_->OnStreamReset(rst_frame);
fkastenholz305e1732019-06-18 05:01:22 -07001595 if (VersionHasIetfQuicFrames(connection_->transport_version())) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001596 // Version 99/IETF QUIC should close just the read side.
1597 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
bncc7d9e0c2019-04-16 10:22:15 -07001598 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001599 } else {
1600 // Google QUIC should close both sides of the stream.
bncc7d9e0c2019-04-16 10:22:15 -07001601 EXPECT_TRUE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001602 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
1603 }
1604}
1605
renjietang28c04b72019-07-01 15:08:09 -07001606TEST_P(QuicStreamTest, WindowUpdateForReadOnlyStream) {
renjietang28c04b72019-07-01 15:08:09 -07001607 Initialize();
1608
1609 QuicStreamId stream_id = QuicUtils::GetFirstUnidirectionalStreamId(
1610 connection_->transport_version(), Perspective::IS_CLIENT);
1611 TestStream stream(stream_id, session_.get(), READ_UNIDIRECTIONAL);
1612 QuicWindowUpdateFrame window_update_frame(kInvalidControlFrameId, stream_id,
1613 0);
1614 EXPECT_CALL(
1615 *connection_,
1616 CloseConnection(
1617 QUIC_WINDOW_UPDATE_RECEIVED_ON_READ_UNIDIRECTIONAL_STREAM,
1618 "WindowUpdateFrame received on READ_UNIDIRECTIONAL stream.", _));
1619 stream.OnWindowUpdateFrame(window_update_frame);
1620}
1621
renjietang15afba32019-10-23 14:32:35 -07001622TEST_P(QuicStreamTest, RstStreamFrameChangesCloseOffset) {
renjietang15afba32019-10-23 14:32:35 -07001623 Initialize();
1624
1625 QuicStreamFrame stream_frame(stream_->id(), true, 0, "abc");
renjietangb38e6352019-10-24 09:38:20 -07001626 EXPECT_CALL(*stream_, OnDataAvailable());
renjietang15afba32019-10-23 14:32:35 -07001627 stream_->OnStreamFrame(stream_frame);
1628 QuicRstStreamFrame rst(kInvalidControlFrameId, stream_->id(),
1629 QUIC_STREAM_CANCELLED, 0u);
1630
1631 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_MULTIPLE_OFFSET, _, _));
1632 stream_->OnStreamReset(rst);
1633}
1634
QUICHE teama6ef0a62019-03-07 20:34:33 -05001635} // namespace
1636} // namespace test
1637} // namespace quic