blob: f30a3be72166f6d864e97db5749d02eb5e2beb5b [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,
308 NOT_RETRANSMISSION, QuicheNullOpt);
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,
327 NOT_RETRANSMISSION, QuicheNullOpt);
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,
renjietang4d992bf2020-03-03 13:01:55 -0800375 NOT_RETRANSMISSION, QuicheNullOpt);
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,
renjietang4d992bf2020-03-03 13:01:55 -0800391 NO_FIN, NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500392 }));
renjietangb38e6352019-10-24 09:38:20 -0700393 EXPECT_CALL(*stream_, OnCanWriteNewData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500394 stream_->OnCanWrite();
fayang8265a2a2019-10-16 11:23:51 -0700395 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500396
397 // And finally the end of the bytes_consumed.
renjietang41a1b412020-02-27 15:05:14 -0800398 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500399 .WillOnce(InvokeWithoutArgs([this]() {
renjietang7c239172020-02-21 13:50:39 -0800400 return session_->ConsumeData(stream_->id(), 2u, 2 * kDataLen - 2,
renjietang4d992bf2020-03-03 13:01:55 -0800401 NO_FIN, NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500402 }));
renjietangb38e6352019-10-24 09:38:20 -0700403 EXPECT_CALL(*stream_, OnCanWriteNewData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500404 stream_->OnCanWrite();
fayang8265a2a2019-10-16 11:23:51 -0700405 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500406}
407
408TEST_P(QuicStreamTest, WriteOrBufferDataReachStreamLimit) {
409 Initialize();
vasilvvc48c8712019-03-11 13:38:16 -0700410 std::string data("aaaaa");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500411 QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - data.length(),
412 stream_);
renjietang41a1b412020-02-27 15:05:14 -0800413 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800414 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500415 stream_->WriteOrBufferData(data, false, nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700416 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500417 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
418 EXPECT_QUIC_BUG(stream_->WriteOrBufferData("a", false, nullptr),
419 "Write too many data via stream");
420}
421
422TEST_P(QuicStreamTest, ConnectionCloseAfterStreamClose) {
423 Initialize();
424
425 QuicStreamPeer::CloseReadSide(stream_);
426 stream_->CloseWriteSide();
bncf6f82b12019-10-30 07:01:01 -0700427 EXPECT_THAT(stream_->stream_error(), IsQuicStreamNoError());
428 EXPECT_THAT(stream_->connection_error(), IsQuicNoError());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500429 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR,
430 ConnectionCloseSource::FROM_SELF);
bncf6f82b12019-10-30 07:01:01 -0700431 EXPECT_THAT(stream_->stream_error(), IsQuicStreamNoError());
432 EXPECT_THAT(stream_->connection_error(), IsQuicNoError());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500433}
434
435TEST_P(QuicStreamTest, RstAlwaysSentIfNoFinSent) {
436 // For flow control accounting, a stream must send either a FIN or a RST frame
437 // before termination.
438 // Test that if no FIN has been sent, we send a RST.
439
440 Initialize();
441 EXPECT_FALSE(fin_sent());
442 EXPECT_FALSE(rst_sent());
443
444 // Write some data, with no FIN.
renjietang41a1b412020-02-27 15:05:14 -0800445 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500446 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800447 return session_->ConsumeData(stream_->id(), 1u, 0u, NO_FIN,
448 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500449 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800450 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 1), false,
451 nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700452 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500453 EXPECT_FALSE(fin_sent());
454 EXPECT_FALSE(rst_sent());
455
456 // Now close the stream, and expect that we send a RST.
457 EXPECT_CALL(*session_, SendRstStream(_, _, _));
fayangd62ea772020-04-17 06:32:16 -0700458 if (session_->break_close_loop()) {
459 stream_->CloseReadSide();
460 stream_->CloseWriteSide();
461 } else {
462 stream_->OnClose();
463 }
zhongyi9fa2be32019-09-10 12:39:01 -0700464 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500465 EXPECT_FALSE(fin_sent());
466 EXPECT_TRUE(rst_sent());
467}
468
469TEST_P(QuicStreamTest, RstNotSentIfFinSent) {
470 // For flow control accounting, a stream must send either a FIN or a RST frame
471 // before termination.
472 // Test that if a FIN has been sent, we don't also send a RST.
473
474 Initialize();
475 EXPECT_FALSE(fin_sent());
476 EXPECT_FALSE(rst_sent());
477
478 // Write some data, with FIN.
renjietang41a1b412020-02-27 15:05:14 -0800479 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500480 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800481 return session_->ConsumeData(stream_->id(), 1u, 0u, FIN,
482 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500483 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800484 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 1), true,
485 nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500486 EXPECT_TRUE(fin_sent());
487 EXPECT_FALSE(rst_sent());
488
489 // Now close the stream, and expect that we do not send a RST.
fayangd62ea772020-04-17 06:32:16 -0700490 if (session_->break_close_loop()) {
491 stream_->CloseReadSide();
492 stream_->CloseWriteSide();
493 } else {
494 stream_->OnClose();
495 }
QUICHE teama6ef0a62019-03-07 20:34:33 -0500496 EXPECT_TRUE(fin_sent());
497 EXPECT_FALSE(rst_sent());
498}
499
500TEST_P(QuicStreamTest, OnlySendOneRst) {
501 // For flow control accounting, a stream must send either a FIN or a RST frame
502 // before termination.
503 // Test that if a stream sends a RST, it doesn't send an additional RST during
504 // OnClose() (this shouldn't be harmful, but we shouldn't do it anyway...)
505
506 Initialize();
507 EXPECT_FALSE(fin_sent());
508 EXPECT_FALSE(rst_sent());
509
510 // Reset the stream.
511 const int expected_resets = 1;
512 EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(expected_resets);
513 stream_->Reset(QUIC_STREAM_CANCELLED);
514 EXPECT_FALSE(fin_sent());
515 EXPECT_TRUE(rst_sent());
516
517 // Now close the stream (any further resets being sent would break the
518 // expectation above).
fayangd62ea772020-04-17 06:32:16 -0700519 if (session_->break_close_loop()) {
520 stream_->CloseReadSide();
521 stream_->CloseWriteSide();
522 } else {
523 stream_->OnClose();
524 }
QUICHE teama6ef0a62019-03-07 20:34:33 -0500525 EXPECT_FALSE(fin_sent());
526 EXPECT_TRUE(rst_sent());
527}
528
529TEST_P(QuicStreamTest, StreamFlowControlMultipleWindowUpdates) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500530 Initialize();
531
532 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we
533 // want to make sure we latch the largest offset we see.
534
535 // Initially should be default.
536 EXPECT_EQ(
renjietang39979d32019-09-13 10:02:13 -0700537 kMinimumFlowControlSendWindow,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500538 QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller()));
539
540 // Check a single WINDOW_UPDATE results in correct offset.
541 QuicWindowUpdateFrame window_update_1(kInvalidControlFrameId, stream_->id(),
renjietang39979d32019-09-13 10:02:13 -0700542 kMinimumFlowControlSendWindow + 5);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500543 stream_->OnWindowUpdateFrame(window_update_1);
renjietangd088eab2019-11-21 14:54:41 -0800544 EXPECT_EQ(window_update_1.max_data, QuicFlowControllerPeer::SendWindowOffset(
545 stream_->flow_controller()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500546
547 // Now send a few more WINDOW_UPDATES and make sure that only the largest is
548 // remembered.
549 QuicWindowUpdateFrame window_update_2(kInvalidControlFrameId, stream_->id(),
550 1);
551 QuicWindowUpdateFrame window_update_3(kInvalidControlFrameId, stream_->id(),
renjietang39979d32019-09-13 10:02:13 -0700552 kMinimumFlowControlSendWindow + 10);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500553 QuicWindowUpdateFrame window_update_4(kInvalidControlFrameId, stream_->id(),
554 5678);
555 stream_->OnWindowUpdateFrame(window_update_2);
556 stream_->OnWindowUpdateFrame(window_update_3);
557 stream_->OnWindowUpdateFrame(window_update_4);
renjietangd088eab2019-11-21 14:54:41 -0800558 EXPECT_EQ(window_update_3.max_data, QuicFlowControllerPeer::SendWindowOffset(
559 stream_->flow_controller()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500560}
561
562TEST_P(QuicStreamTest, FrameStats) {
563 Initialize();
564
565 EXPECT_EQ(0, stream_->num_frames_received());
566 EXPECT_EQ(0, stream_->num_duplicate_frames_received());
renjietangb38e6352019-10-24 09:38:20 -0700567 QuicStreamFrame frame(stream_->id(), false, 0, ".");
568 EXPECT_CALL(*stream_, OnDataAvailable()).Times(2);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500569 stream_->OnStreamFrame(frame);
570 EXPECT_EQ(1, stream_->num_frames_received());
571 EXPECT_EQ(0, stream_->num_duplicate_frames_received());
572 stream_->OnStreamFrame(frame);
573 EXPECT_EQ(2, stream_->num_frames_received());
574 EXPECT_EQ(1, stream_->num_duplicate_frames_received());
renjietangb38e6352019-10-24 09:38:20 -0700575 QuicStreamFrame frame2(stream_->id(), false, 1, "abc");
576 stream_->OnStreamFrame(frame2);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500577}
578
579// Verify that when we receive a packet which violates flow control (i.e. sends
580// too much data on the stream) that the stream sequencer never sees this frame,
581// as we check for violation and close the connection early.
582TEST_P(QuicStreamTest, StreamSequencerNeverSeesPacketsViolatingFlowControl) {
583 Initialize();
584
585 // Receive a stream frame that violates flow control: the byte offset is
586 // higher than the receive window offset.
587 QuicStreamFrame frame(stream_->id(), false,
renjietangb38e6352019-10-24 09:38:20 -0700588 kInitialSessionFlowControlWindowForTest + 1, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500589 EXPECT_GT(frame.offset, QuicFlowControllerPeer::ReceiveWindowOffset(
590 stream_->flow_controller()));
591
592 // Stream should not accept the frame, and the connection should be closed.
593 EXPECT_CALL(*connection_,
594 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _));
595 stream_->OnStreamFrame(frame);
596}
597
598// Verify that after the consumer calls StopReading(), the stream still sends
599// flow control updates.
600TEST_P(QuicStreamTest, StopReadingSendsFlowControl) {
601 Initialize();
602
603 stream_->StopReading();
604
605 // Connection should not get terminated due to flow control errors.
606 EXPECT_CALL(*connection_,
607 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _))
608 .Times(0);
609 EXPECT_CALL(*connection_, SendControlFrame(_))
610 .Times(AtLeast(1))
bnc5b3c3be2019-06-25 10:37:09 -0700611 .WillRepeatedly(Invoke(&ClearControlFrame));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500612
vasilvvc48c8712019-03-11 13:38:16 -0700613 std::string data(1000, 'x');
QUICHE teama6ef0a62019-03-07 20:34:33 -0500614 for (QuicStreamOffset offset = 0;
615 offset < 2 * kInitialStreamFlowControlWindowForTest;
616 offset += data.length()) {
617 QuicStreamFrame frame(stream_->id(), false, offset, data);
618 stream_->OnStreamFrame(frame);
619 }
620 EXPECT_LT(
621 kInitialStreamFlowControlWindowForTest,
622 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
623}
624
625TEST_P(QuicStreamTest, FinalByteOffsetFromFin) {
626 Initialize();
627
renjietang6c066562019-11-04 17:05:59 -0800628 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500629
renjietangb38e6352019-10-24 09:38:20 -0700630 QuicStreamFrame stream_frame_no_fin(stream_->id(), false, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500631 stream_->OnStreamFrame(stream_frame_no_fin);
renjietang6c066562019-11-04 17:05:59 -0800632 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500633
renjietangb38e6352019-10-24 09:38:20 -0700634 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500635 stream_->OnStreamFrame(stream_frame_with_fin);
renjietang6c066562019-11-04 17:05:59 -0800636 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500637}
638
639TEST_P(QuicStreamTest, FinalByteOffsetFromRst) {
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, 1234);
645 stream_->OnStreamReset(rst_frame);
renjietang6c066562019-11-04 17:05:59 -0800646 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500647}
648
649TEST_P(QuicStreamTest, InvalidFinalByteOffsetFromRst) {
650 Initialize();
651
renjietang6c066562019-11-04 17:05:59 -0800652 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500653 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
654 QUIC_STREAM_CANCELLED, 0xFFFFFFFFFFFF);
655 // Stream should not accept the frame, and the connection should be closed.
656 EXPECT_CALL(*connection_,
657 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _));
658 stream_->OnStreamReset(rst_frame);
renjietang6c066562019-11-04 17:05:59 -0800659 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
fayangd62ea772020-04-17 06:32:16 -0700660 if (session_->break_close_loop()) {
661 stream_->CloseReadSide();
662 stream_->CloseWriteSide();
663 } else {
664 stream_->OnClose();
665 }
QUICHE teama6ef0a62019-03-07 20:34:33 -0500666}
667
668TEST_P(QuicStreamTest, FinalByteOffsetFromZeroLengthStreamFrame) {
669 // When receiving Trailers, an empty stream frame is created with the FIN set,
670 // and is passed to OnStreamFrame. The Trailers may be sent in advance of
671 // queued body bytes being sent, and thus the final byte offset may exceed
672 // current flow control limits. Flow control should only be concerned with
673 // data that has actually been sent/received, so verify that flow control
674 // ignores such a stream frame.
675 Initialize();
676
renjietang6c066562019-11-04 17:05:59 -0800677 EXPECT_FALSE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500678 const QuicStreamOffset kByteOffsetExceedingFlowControlWindow =
679 kInitialSessionFlowControlWindowForTest + 1;
680 const QuicStreamOffset current_stream_flow_control_offset =
681 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller());
682 const QuicStreamOffset current_connection_flow_control_offset =
683 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller());
684 ASSERT_GT(kByteOffsetExceedingFlowControlWindow,
685 current_stream_flow_control_offset);
686 ASSERT_GT(kByteOffsetExceedingFlowControlWindow,
687 current_connection_flow_control_offset);
688 QuicStreamFrame zero_length_stream_frame_with_fin(
689 stream_->id(), /*fin=*/true, kByteOffsetExceedingFlowControlWindow,
dmcardlecf0bfcf2019-12-13 08:08:21 -0800690 quiche::QuicheStringPiece());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500691 EXPECT_EQ(0, zero_length_stream_frame_with_fin.data_length);
692
693 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
694 stream_->OnStreamFrame(zero_length_stream_frame_with_fin);
renjietang6c066562019-11-04 17:05:59 -0800695 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500696
697 // The flow control receive offset values should not have changed.
698 EXPECT_EQ(
699 current_stream_flow_control_offset,
700 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
701 EXPECT_EQ(
702 current_connection_flow_control_offset,
703 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller()));
704}
705
706TEST_P(QuicStreamTest, OnStreamResetOffsetOverflow) {
707 Initialize();
708 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
709 QUIC_STREAM_CANCELLED, kMaxStreamLength + 1);
710 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
711 stream_->OnStreamReset(rst_frame);
712}
713
714TEST_P(QuicStreamTest, OnStreamFrameUpperLimit) {
715 Initialize();
716
717 // Modify receive window offset and sequencer buffer total_bytes_read_ to
718 // avoid flow control violation.
719 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
720 kMaxStreamLength + 5u);
721 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
722 kMaxStreamLength + 5u);
723 QuicStreamSequencerPeer::SetFrameBufferTotalBytesRead(
724 QuicStreamPeer::sequencer(stream_), kMaxStreamLength - 10u);
725
726 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _))
727 .Times(0);
renjietangb38e6352019-10-24 09:38:20 -0700728 QuicStreamFrame stream_frame(stream_->id(), false, kMaxStreamLength - 1, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500729 stream_->OnStreamFrame(stream_frame);
renjietangb38e6352019-10-24 09:38:20 -0700730 QuicStreamFrame stream_frame2(stream_->id(), true, kMaxStreamLength, "");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500731 stream_->OnStreamFrame(stream_frame2);
732}
733
734TEST_P(QuicStreamTest, StreamTooLong) {
735 Initialize();
736 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _))
737 .Times(1);
renjietangb38e6352019-10-24 09:38:20 -0700738 QuicStreamFrame stream_frame(stream_->id(), false, kMaxStreamLength, ".");
dmcardlecf0bfcf2019-12-13 08:08:21 -0800739 EXPECT_QUIC_PEER_BUG(
740 stream_->OnStreamFrame(stream_frame),
741 quiche::QuicheStrCat("Receive stream frame on stream ", stream_->id(),
742 " reaches max stream length"));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500743}
744
renjietang9bf25642019-10-10 10:21:15 -0700745TEST_P(QuicStreamTest, SetDrainingIncomingOutgoing) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500746 // Don't have incoming data consumed.
747 Initialize();
748
749 // Incoming data with FIN.
renjietangb38e6352019-10-24 09:38:20 -0700750 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500751 stream_->OnStreamFrame(stream_frame_with_fin);
752 // The FIN has been received but not consumed.
renjietang6c066562019-11-04 17:05:59 -0800753 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500754 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
755 EXPECT_FALSE(stream_->reading_stopped());
756
fayang01591ae2020-04-23 14:14:56 -0700757 EXPECT_EQ(1u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500758
759 // Outgoing data with FIN.
renjietang41a1b412020-02-27 15:05:14 -0800760 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500761 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800762 return session_->ConsumeData(stream_->id(), 2u, 0u, FIN,
763 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500764 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800765 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true,
766 nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500767 EXPECT_TRUE(stream_->write_side_closed());
768
fayangbe6d6642020-04-16 14:15:34 -0700769 EXPECT_EQ(1u, session_->GetNumDrainingStreams());
fayang01591ae2020-04-23 14:14:56 -0700770 EXPECT_EQ(0u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500771}
772
renjietang9bf25642019-10-10 10:21:15 -0700773TEST_P(QuicStreamTest, SetDrainingOutgoingIncoming) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500774 // Don't have incoming data consumed.
775 Initialize();
776
777 // Outgoing data with FIN.
renjietang41a1b412020-02-27 15:05:14 -0800778 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -0500779 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -0800780 return session_->ConsumeData(stream_->id(), 2u, 0u, FIN,
781 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500782 }));
dmcardlecf0bfcf2019-12-13 08:08:21 -0800783 stream_->WriteOrBufferData(quiche::QuicheStringPiece(kData1, 2), true,
784 nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500785 EXPECT_TRUE(stream_->write_side_closed());
786
fayang01591ae2020-04-23 14:14:56 -0700787 EXPECT_EQ(1u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500788
789 // Incoming data with FIN.
renjietangb38e6352019-10-24 09:38:20 -0700790 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, ".");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500791 stream_->OnStreamFrame(stream_frame_with_fin);
792 // The FIN has been received but not consumed.
renjietang6c066562019-11-04 17:05:59 -0800793 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500794 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
795 EXPECT_FALSE(stream_->reading_stopped());
796
fayangbe6d6642020-04-16 14:15:34 -0700797 EXPECT_EQ(1u, session_->GetNumDrainingStreams());
fayang01591ae2020-04-23 14:14:56 -0700798 EXPECT_EQ(0u, QuicSessionPeer::GetNumOpenDynamicStreams(session_.get()));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500799}
800
801TEST_P(QuicStreamTest, EarlyResponseFinHandling) {
802 // Verify that if the server completes the response before reading the end of
803 // the request, the received FIN is recorded.
804
805 Initialize();
806 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
renjietang41a1b412020-02-27 15:05:14 -0800807 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800808 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500809
810 // Receive data for the request.
renjietangb38e6352019-10-24 09:38:20 -0700811 EXPECT_CALL(*stream_, OnDataAvailable()).Times(1);
812 QuicStreamFrame frame1(stream_->id(), false, 0, "Start");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500813 stream_->OnStreamFrame(frame1);
814 // When QuicSimpleServerStream sends the response, it calls
815 // QuicStream::CloseReadSide() first.
816 QuicStreamPeer::CloseReadSide(stream_);
817 // Send data and FIN for the response.
818 stream_->WriteOrBufferData(kData1, false, nullptr);
819 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
820 // Receive remaining data and FIN for the request.
renjietangb38e6352019-10-24 09:38:20 -0700821 QuicStreamFrame frame2(stream_->id(), true, 0, "End");
QUICHE teama6ef0a62019-03-07 20:34:33 -0500822 stream_->OnStreamFrame(frame2);
823 EXPECT_TRUE(stream_->fin_received());
renjietang6c066562019-11-04 17:05:59 -0800824 EXPECT_TRUE(stream_->HasReceivedFinalOffset());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500825}
826
827TEST_P(QuicStreamTest, StreamWaitsForAcks) {
828 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800829 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800830 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500831 // Stream is not waiting for acks initially.
832 EXPECT_FALSE(stream_->IsWaitingForAcks());
833 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
zhongyi9fa2be32019-09-10 12:39:01 -0700834 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500835
836 // Send kData1.
837 stream_->WriteOrBufferData(kData1, false, nullptr);
fayang8265a2a2019-10-16 11:23:51 -0700838 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500839 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
840 EXPECT_TRUE(stream_->IsWaitingForAcks());
841 QuicByteCount newly_acked_length = 0;
842 EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800843 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500844 &newly_acked_length));
845 EXPECT_EQ(9u, newly_acked_length);
846 // Stream is not waiting for acks as all sent data is acked.
847 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700848 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500849 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
850
851 // Send kData2.
852 stream_->WriteOrBufferData(kData2, false, nullptr);
853 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700854 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500855 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
856 // Send FIN.
857 stream_->WriteOrBufferData("", true, nullptr);
858 // Fin only frame is not stored in send buffer.
859 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
860
861 // kData2 is retransmitted.
862 stream_->OnStreamFrameRetransmitted(9, 9, false);
863
864 // kData2 is acked.
865 EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800866 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500867 &newly_acked_length));
868 EXPECT_EQ(9u, newly_acked_length);
869 // Stream is waiting for acks as FIN is not acked.
870 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700871 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500872 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
873
874 // FIN is acked.
875 EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 0, true, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800876 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500877 &newly_acked_length));
878 EXPECT_EQ(0u, newly_acked_length);
879 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700880 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500881 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
882}
883
884TEST_P(QuicStreamTest, StreamDataGetAckedOutOfOrder) {
885 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800886 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800887 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500888 // Send data.
889 stream_->WriteOrBufferData(kData1, false, nullptr);
890 stream_->WriteOrBufferData(kData1, false, nullptr);
891 stream_->WriteOrBufferData(kData1, false, nullptr);
892 stream_->WriteOrBufferData("", true, nullptr);
893 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
894 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700895 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500896 QuicByteCount newly_acked_length = 0;
897 EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800898 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500899 &newly_acked_length));
fayang8265a2a2019-10-16 11:23:51 -0700900 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500901 EXPECT_EQ(9u, newly_acked_length);
902 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
903 EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800904 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500905 &newly_acked_length));
fayang8265a2a2019-10-16 11:23:51 -0700906 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500907 EXPECT_EQ(9u, newly_acked_length);
908 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
909 EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800910 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500911 &newly_acked_length));
fayang8265a2a2019-10-16 11:23:51 -0700912 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500913 EXPECT_EQ(9u, newly_acked_length);
914 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
915 // FIN is not acked yet.
916 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700917 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500918 EXPECT_TRUE(stream_->OnStreamFrameAcked(27, 0, true, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -0800919 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -0500920 &newly_acked_length));
921 EXPECT_EQ(0u, newly_acked_length);
922 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700923 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500924}
925
926TEST_P(QuicStreamTest, CancelStream) {
927 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800928 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800929 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500930 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700931 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500932 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
933
934 stream_->WriteOrBufferData(kData1, false, nullptr);
935 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700936 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500937 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
938 // Cancel stream.
939 stream_->Reset(QUIC_STREAM_NO_ERROR);
940 // stream still waits for acks as the error code is QUIC_STREAM_NO_ERROR, and
941 // data is going to be retransmitted.
942 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700943 EXPECT_TRUE(session_->HasUnackedStreamData());
zhongyi1b2f7832019-06-14 13:31:34 -0700944 EXPECT_CALL(*connection_,
945 OnStreamReset(stream_->id(), QUIC_STREAM_CANCELLED));
renjietangeab92852019-10-25 12:16:14 -0700946 EXPECT_CALL(*connection_, SendControlFrame(_))
947 .Times(AtLeast(1))
948 .WillRepeatedly(Invoke(&ClearControlFrame));
zhongyi1b2f7832019-06-14 13:31:34 -0700949 EXPECT_CALL(*session_, SendRstStream(stream_->id(), QUIC_STREAM_CANCELLED, 9))
950 .WillOnce(InvokeWithoutArgs([this]() {
renjietang61cc2452019-11-26 10:57:10 -0800951 session_->ReallySendRstStream(stream_->id(), QUIC_STREAM_CANCELLED,
952 stream_->stream_bytes_written());
zhongyi1b2f7832019-06-14 13:31:34 -0700953 }));
954
QUICHE teama6ef0a62019-03-07 20:34:33 -0500955 stream_->Reset(QUIC_STREAM_CANCELLED);
956 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
957 // Stream stops waiting for acks as data is not going to be retransmitted.
958 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700959 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500960}
961
962TEST_P(QuicStreamTest, RstFrameReceivedStreamNotFinishSending) {
renjietang9bf25642019-10-10 10:21:15 -0700963 if (VersionHasIetfQuicFrames(GetParam().transport_version)) {
964 // In IETF QUIC, receiving a RESET_STREAM will only close the read side. The
965 // stream itself is not closed and will not send reset.
966 return;
967 }
968
QUICHE teama6ef0a62019-03-07 20:34:33 -0500969 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800970 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800971 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500972 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700973 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500974 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
975
976 stream_->WriteOrBufferData(kData1, false, nullptr);
977 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -0700978 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500979 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
980
981 // RST_STREAM received.
982 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
983 QUIC_STREAM_CANCELLED, 9);
984 EXPECT_CALL(*session_,
985 SendRstStream(stream_->id(), QUIC_RST_ACKNOWLEDGEMENT, 9));
986 stream_->OnStreamReset(rst_frame);
987 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
988 // Stream stops waiting for acks as it does not finish sending and rst is
989 // sent.
990 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700991 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500992}
993
994TEST_P(QuicStreamTest, RstFrameReceivedStreamFinishSending) {
995 Initialize();
renjietang41a1b412020-02-27 15:05:14 -0800996 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -0800997 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500998 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -0700999 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001000 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1001
1002 stream_->WriteOrBufferData(kData1, true, nullptr);
1003 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001004 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001005
1006 // RST_STREAM received.
1007 EXPECT_CALL(*session_, SendRstStream(_, _, _)).Times(0);
1008 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
1009 QUIC_STREAM_CANCELLED, 1234);
1010 stream_->OnStreamReset(rst_frame);
1011 // Stream still waits for acks as it finishes sending and has unacked data.
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_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1015}
1016
1017TEST_P(QuicStreamTest, ConnectionClosed) {
1018 Initialize();
renjietang41a1b412020-02-27 15:05:14 -08001019 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001020 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001021 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001022 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001023 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1024
1025 stream_->WriteOrBufferData(kData1, false, nullptr);
1026 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001027 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001028 EXPECT_CALL(*session_,
1029 SendRstStream(stream_->id(), QUIC_RST_ACKNOWLEDGEMENT, 9));
1030 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR,
1031 ConnectionCloseSource::FROM_SELF);
1032 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1033 // Stream stops waiting for acks as connection is going to close.
1034 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001035 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001036}
1037
1038TEST_P(QuicStreamTest, CanWriteNewDataAfterData) {
wub49855982019-05-01 14:16:26 -07001039 SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001040 Initialize();
1041 EXPECT_TRUE(stream_->CanWriteNewDataAfterData(99));
1042 EXPECT_FALSE(stream_->CanWriteNewDataAfterData(100));
1043}
1044
1045TEST_P(QuicStreamTest, WriteBufferedData) {
1046 // Set buffered data low water mark to be 100.
wub49855982019-05-01 14:16:26 -07001047 SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001048
1049 Initialize();
vasilvvc48c8712019-03-11 13:38:16 -07001050 std::string data(1024, 'a');
QUICHE teama6ef0a62019-03-07 20:34:33 -05001051 EXPECT_TRUE(stream_->CanWriteNewData());
1052
1053 // Testing WriteOrBufferData.
renjietang41a1b412020-02-27 15:05:14 -08001054 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001055 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001056 return session_->ConsumeData(stream_->id(), 100u, 0u, NO_FIN,
1057 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001058 }));
1059 stream_->WriteOrBufferData(data, false, nullptr);
1060 stream_->WriteOrBufferData(data, false, nullptr);
1061 stream_->WriteOrBufferData(data, false, nullptr);
zhongyi1b2f7832019-06-14 13:31:34 -07001062 EXPECT_TRUE(stream_->IsWaitingForAcks());
1063
QUICHE teama6ef0a62019-03-07 20:34:33 -05001064 // Verify all data is saved.
1065 EXPECT_EQ(3 * data.length() - 100, stream_->BufferedDataBytes());
1066
renjietang41a1b412020-02-27 15:05:14 -08001067 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001068 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001069 return session_->ConsumeData(stream_->id(), 100, 100u, NO_FIN,
1070 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001071 }));
1072 // Buffered data size > threshold, do not ask upper layer for more data.
1073 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(0);
1074 stream_->OnCanWrite();
1075 EXPECT_EQ(3 * data.length() - 200, stream_->BufferedDataBytes());
1076 EXPECT_FALSE(stream_->CanWriteNewData());
1077
1078 // Send buffered data to make buffered data size < threshold.
dschinazif1e7b422020-04-30 12:21:28 -07001079 QuicByteCount data_to_write =
1080 3 * data.length() - 200 -
1081 GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1;
renjietang41a1b412020-02-27 15:05:14 -08001082 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001083 .WillOnce(InvokeWithoutArgs([this, data_to_write]() {
renjietang7c239172020-02-21 13:50:39 -08001084 return session_->ConsumeData(stream_->id(), data_to_write, 200u, NO_FIN,
renjietang4d992bf2020-03-03 13:01:55 -08001085 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001086 }));
1087 // Buffered data size < threshold, ask upper layer for more data.
1088 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1089 stream_->OnCanWrite();
dschinazi696ee602019-04-25 16:05:35 -07001090 EXPECT_EQ(static_cast<uint64_t>(
1091 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001092 stream_->BufferedDataBytes());
1093 EXPECT_TRUE(stream_->CanWriteNewData());
1094
1095 // Flush all buffered data.
renjietang41a1b412020-02-27 15:05:14 -08001096 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001097 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001098 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1099 stream_->OnCanWrite();
1100 EXPECT_EQ(0u, stream_->BufferedDataBytes());
1101 EXPECT_FALSE(stream_->HasBufferedData());
1102 EXPECT_TRUE(stream_->CanWriteNewData());
1103
1104 // Testing Writev.
renjietang41a1b412020-02-27 15:05:14 -08001105 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001106 .WillOnce(Return(QuicConsumedData(0, false)));
1107 struct iovec iov = {const_cast<char*>(data.data()), data.length()};
1108 QuicMemSliceStorage storage(
1109 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1110 1024);
1111 QuicConsumedData consumed = stream_->WriteMemSlices(storage.ToSpan(), false);
1112
1113 // There is no buffered data before, all data should be consumed without
1114 // respecting buffered data upper limit.
1115 EXPECT_EQ(data.length(), consumed.bytes_consumed);
1116 EXPECT_FALSE(consumed.fin_consumed);
1117 EXPECT_EQ(data.length(), stream_->BufferedDataBytes());
1118 EXPECT_FALSE(stream_->CanWriteNewData());
1119
renjietang41a1b412020-02-27 15:05:14 -08001120 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001121 QuicMemSliceStorage storage2(
1122 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1123 1024);
1124 consumed = stream_->WriteMemSlices(storage2.ToSpan(), false);
1125 // No Data can be consumed as buffered data is beyond upper limit.
1126 EXPECT_EQ(0u, consumed.bytes_consumed);
1127 EXPECT_FALSE(consumed.fin_consumed);
1128 EXPECT_EQ(data.length(), stream_->BufferedDataBytes());
1129
1130 data_to_write =
1131 data.length() - GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1;
renjietang41a1b412020-02-27 15:05:14 -08001132 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001133 .WillOnce(InvokeWithoutArgs([this, data_to_write]() {
renjietang7c239172020-02-21 13:50:39 -08001134 return session_->ConsumeData(stream_->id(), data_to_write, 0u, NO_FIN,
renjietang4d992bf2020-03-03 13:01:55 -08001135 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001136 }));
1137
1138 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1139 stream_->OnCanWrite();
dschinazi696ee602019-04-25 16:05:35 -07001140 EXPECT_EQ(static_cast<uint64_t>(
1141 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001142 stream_->BufferedDataBytes());
1143 EXPECT_TRUE(stream_->CanWriteNewData());
1144
renjietang41a1b412020-02-27 15:05:14 -08001145 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001146 // All data can be consumed as buffered data is below upper limit.
1147 QuicMemSliceStorage storage3(
1148 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1149 1024);
1150 consumed = stream_->WriteMemSlices(storage3.ToSpan(), false);
1151 EXPECT_EQ(data.length(), consumed.bytes_consumed);
1152 EXPECT_FALSE(consumed.fin_consumed);
1153 EXPECT_EQ(data.length() + GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1,
1154 stream_->BufferedDataBytes());
1155 EXPECT_FALSE(stream_->CanWriteNewData());
1156}
1157
1158TEST_P(QuicStreamTest, WritevDataReachStreamLimit) {
1159 Initialize();
vasilvvc48c8712019-03-11 13:38:16 -07001160 std::string data("aaaaa");
QUICHE teama6ef0a62019-03-07 20:34:33 -05001161 QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - data.length(),
1162 stream_);
renjietang41a1b412020-02-27 15:05:14 -08001163 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001164 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001165 struct iovec iov = {const_cast<char*>(data.data()), 5u};
1166 QuicMemSliceStorage storage(
1167 &iov, 1, session_->connection()->helper()->GetStreamSendBufferAllocator(),
1168 1024);
1169 QuicConsumedData consumed = stream_->WriteMemSlices(storage.ToSpan(), false);
1170 EXPECT_EQ(data.length(), consumed.bytes_consumed);
1171 struct iovec iov2 = {const_cast<char*>(data.data()), 1u};
1172 QuicMemSliceStorage storage2(
1173 &iov2, 1,
1174 session_->connection()->helper()->GetStreamSendBufferAllocator(), 1024);
1175 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
1176 EXPECT_QUIC_BUG(stream_->WriteMemSlices(storage2.ToSpan(), false),
1177 "Write too many data via stream");
1178}
1179
1180TEST_P(QuicStreamTest, WriteMemSlices) {
1181 // Set buffered data low water mark to be 100.
wub49855982019-05-01 14:16:26 -07001182 SetQuicFlag(FLAGS_quic_buffered_data_threshold, 100);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001183
1184 Initialize();
1185 char data[1024];
nharper6b7aa8b2020-04-30 17:23:35 -07001186 std::vector<std::pair<char*, size_t>> buffers;
bnc4e9283d2019-12-17 07:08:57 -08001187 buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data)));
1188 buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data)));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001189 QuicTestMemSliceVector vector1(buffers);
1190 QuicTestMemSliceVector vector2(buffers);
1191 QuicMemSliceSpan span1 = vector1.span();
1192 QuicMemSliceSpan span2 = vector2.span();
1193
renjietang41a1b412020-02-27 15:05:14 -08001194 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001195 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001196 return session_->ConsumeData(stream_->id(), 100u, 0u, NO_FIN,
1197 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001198 }));
1199 // There is no buffered data before, all data should be consumed.
1200 QuicConsumedData consumed = stream_->WriteMemSlices(span1, false);
1201 EXPECT_EQ(2048u, consumed.bytes_consumed);
1202 EXPECT_FALSE(consumed.fin_consumed);
bnc4e9283d2019-12-17 07:08:57 -08001203 EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) - 100, stream_->BufferedDataBytes());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001204 EXPECT_FALSE(stream_->fin_buffered());
1205
renjietang41a1b412020-02-27 15:05:14 -08001206 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001207 // No Data can be consumed as buffered data is beyond upper limit.
1208 consumed = stream_->WriteMemSlices(span2, true);
1209 EXPECT_EQ(0u, consumed.bytes_consumed);
1210 EXPECT_FALSE(consumed.fin_consumed);
bnc4e9283d2019-12-17 07:08:57 -08001211 EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) - 100, stream_->BufferedDataBytes());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001212 EXPECT_FALSE(stream_->fin_buffered());
1213
dschinazif1e7b422020-04-30 12:21:28 -07001214 QuicByteCount data_to_write =
1215 2 * QUICHE_ARRAYSIZE(data) - 100 -
1216 GetQuicFlag(FLAGS_quic_buffered_data_threshold) + 1;
renjietang41a1b412020-02-27 15:05:14 -08001217 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001218 .WillOnce(InvokeWithoutArgs([this, data_to_write]() {
renjietang7c239172020-02-21 13:50:39 -08001219 return session_->ConsumeData(stream_->id(), data_to_write, 100u, NO_FIN,
renjietang4d992bf2020-03-03 13:01:55 -08001220 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001221 }));
1222 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
1223 stream_->OnCanWrite();
dschinazi696ee602019-04-25 16:05:35 -07001224 EXPECT_EQ(static_cast<uint64_t>(
1225 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001226 stream_->BufferedDataBytes());
1227 // Try to write slices2 again.
renjietang41a1b412020-02-27 15:05:14 -08001228 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).Times(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001229 consumed = stream_->WriteMemSlices(span2, true);
1230 EXPECT_EQ(2048u, consumed.bytes_consumed);
1231 EXPECT_TRUE(consumed.fin_consumed);
bnc4e9283d2019-12-17 07:08:57 -08001232 EXPECT_EQ(2 * QUICHE_ARRAYSIZE(data) +
QUICHE teama6ef0a62019-03-07 20:34:33 -05001233 GetQuicFlag(FLAGS_quic_buffered_data_threshold) - 1,
1234 stream_->BufferedDataBytes());
1235 EXPECT_TRUE(stream_->fin_buffered());
1236
1237 // Flush all buffered data.
renjietang41a1b412020-02-27 15:05:14 -08001238 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001239 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001240 stream_->OnCanWrite();
1241 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(0);
1242 EXPECT_FALSE(stream_->HasBufferedData());
1243 EXPECT_TRUE(stream_->write_side_closed());
1244}
1245
1246TEST_P(QuicStreamTest, WriteMemSlicesReachStreamLimit) {
1247 Initialize();
1248 QuicStreamPeer::SetStreamBytesWritten(kMaxStreamLength - 5u, stream_);
1249 char data[5];
nharper6b7aa8b2020-04-30 17:23:35 -07001250 std::vector<std::pair<char*, size_t>> buffers;
bnc4e9283d2019-12-17 07:08:57 -08001251 buffers.push_back(std::make_pair(data, QUICHE_ARRAYSIZE(data)));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001252 QuicTestMemSliceVector vector1(buffers);
1253 QuicMemSliceSpan span1 = vector1.span();
renjietang41a1b412020-02-27 15:05:14 -08001254 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001255 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001256 return session_->ConsumeData(stream_->id(), 5u, 0u, NO_FIN,
1257 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001258 }));
1259 // There is no buffered data before, all data should be consumed.
1260 QuicConsumedData consumed = stream_->WriteMemSlices(span1, false);
1261 EXPECT_EQ(5u, consumed.bytes_consumed);
1262
nharper6b7aa8b2020-04-30 17:23:35 -07001263 std::vector<std::pair<char*, size_t>> buffers2;
QUICHE teama6ef0a62019-03-07 20:34:33 -05001264 buffers2.push_back(std::make_pair(data, 1u));
1265 QuicTestMemSliceVector vector2(buffers);
1266 QuicMemSliceSpan span2 = vector2.span();
1267 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_LENGTH_OVERFLOW, _, _));
1268 EXPECT_QUIC_BUG(stream_->WriteMemSlices(span2, false),
1269 "Write too many data via stream");
1270}
1271
1272TEST_P(QuicStreamTest, StreamDataGetAckedMultipleTimes) {
1273 Initialize();
renjietang41a1b412020-02-27 15:05:14 -08001274 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001275 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
zhongyi1b2f7832019-06-14 13:31:34 -07001276 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001277 EXPECT_FALSE(session_->HasUnackedStreamData());
zhongyi1b2f7832019-06-14 13:31:34 -07001278
QUICHE teama6ef0a62019-03-07 20:34:33 -05001279 // Send [0, 27) and fin.
1280 stream_->WriteOrBufferData(kData1, false, nullptr);
1281 stream_->WriteOrBufferData(kData1, false, nullptr);
1282 stream_->WriteOrBufferData(kData1, true, nullptr);
1283 EXPECT_EQ(3u, QuicStreamPeer::SendBuffer(stream_).size());
1284 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001285 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001286 // Ack [0, 9), [5, 22) and [18, 26)
1287 // Verify [0, 9) 9 bytes are acked.
1288 QuicByteCount newly_acked_length = 0;
1289 EXPECT_TRUE(stream_->OnStreamFrameAcked(0, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001290 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001291 &newly_acked_length));
1292 EXPECT_EQ(9u, newly_acked_length);
1293 EXPECT_EQ(2u, QuicStreamPeer::SendBuffer(stream_).size());
1294 // Verify [9, 22) 13 bytes are acked.
1295 EXPECT_TRUE(stream_->OnStreamFrameAcked(5, 17, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001296 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001297 &newly_acked_length));
1298 EXPECT_EQ(13u, newly_acked_length);
1299 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1300 // Verify [22, 26) 4 bytes are acked.
1301 EXPECT_TRUE(stream_->OnStreamFrameAcked(18, 8, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001302 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001303 &newly_acked_length));
1304 EXPECT_EQ(4u, newly_acked_length);
1305 EXPECT_EQ(1u, QuicStreamPeer::SendBuffer(stream_).size());
1306 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001307 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001308
1309 // Ack [0, 27). Verify [26, 27) 1 byte is acked.
1310 EXPECT_TRUE(stream_->OnStreamFrameAcked(26, 1, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001311 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001312 &newly_acked_length));
1313 EXPECT_EQ(1u, newly_acked_length);
1314 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1315 EXPECT_TRUE(stream_->IsWaitingForAcks());
fayang8265a2a2019-10-16 11:23:51 -07001316 EXPECT_TRUE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001317
1318 // Ack Fin.
1319 EXPECT_TRUE(stream_->OnStreamFrameAcked(27, 0, true, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001320 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001321 &newly_acked_length));
1322 EXPECT_EQ(0u, newly_acked_length);
1323 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1324 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001325 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001326
1327 // Ack [10, 27) and fin. No new data is acked.
QUICHE team2f5f30b2020-02-18 08:52:28 -08001328 EXPECT_FALSE(
1329 stream_->OnStreamFrameAcked(10, 17, true, QuicTime::Delta::Zero(),
1330 QuicTime::Zero(), &newly_acked_length));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001331 EXPECT_EQ(0u, newly_acked_length);
1332 EXPECT_EQ(0u, QuicStreamPeer::SendBuffer(stream_).size());
1333 EXPECT_FALSE(stream_->IsWaitingForAcks());
zhongyi9fa2be32019-09-10 12:39:01 -07001334 EXPECT_FALSE(session_->HasUnackedStreamData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001335}
1336
1337TEST_P(QuicStreamTest, OnStreamFrameLost) {
1338 Initialize();
1339
1340 // Send [0, 9).
renjietang41a1b412020-02-27 15:05:14 -08001341 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001342 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001343 stream_->WriteOrBufferData(kData1, false, nullptr);
1344 EXPECT_FALSE(stream_->HasBufferedData());
1345 EXPECT_TRUE(stream_->IsStreamFrameOutstanding(0, 9, false));
1346
1347 // Try to send [9, 27), but connection is blocked.
renjietang41a1b412020-02-27 15:05:14 -08001348 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001349 .WillOnce(Return(QuicConsumedData(0, false)));
1350 stream_->WriteOrBufferData(kData2, false, nullptr);
1351 stream_->WriteOrBufferData(kData2, false, nullptr);
1352 EXPECT_TRUE(stream_->HasBufferedData());
1353 EXPECT_FALSE(stream_->HasPendingRetransmission());
1354
1355 // Lost [0, 9). When stream gets a chance to write, only lost data is
1356 // transmitted.
1357 stream_->OnStreamFrameLost(0, 9, false);
1358 EXPECT_TRUE(stream_->HasPendingRetransmission());
renjietang41a1b412020-02-27 15:05:14 -08001359 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001360 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietangb38e6352019-10-24 09:38:20 -07001361 EXPECT_CALL(*stream_, OnCanWriteNewData()).Times(1);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001362 stream_->OnCanWrite();
1363 EXPECT_FALSE(stream_->HasPendingRetransmission());
1364 EXPECT_TRUE(stream_->HasBufferedData());
1365
1366 // This OnCanWrite causes [9, 27) to be sent.
renjietang41a1b412020-02-27 15:05:14 -08001367 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001368 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001369 stream_->OnCanWrite();
1370 EXPECT_FALSE(stream_->HasBufferedData());
1371
1372 // Send a fin only frame.
renjietang41a1b412020-02-27 15:05:14 -08001373 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001374 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001375 stream_->WriteOrBufferData("", true, nullptr);
1376
1377 // Lost [9, 27) and fin.
1378 stream_->OnStreamFrameLost(9, 18, false);
1379 stream_->OnStreamFrameLost(27, 0, true);
1380 EXPECT_TRUE(stream_->HasPendingRetransmission());
1381
1382 // Ack [9, 18).
1383 QuicByteCount newly_acked_length = 0;
1384 EXPECT_TRUE(stream_->OnStreamFrameAcked(9, 9, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001385 QuicTime::Zero(),
QUICHE teama6ef0a62019-03-07 20:34:33 -05001386 &newly_acked_length));
1387 EXPECT_EQ(9u, newly_acked_length);
1388 EXPECT_FALSE(stream_->IsStreamFrameOutstanding(9, 3, false));
1389 EXPECT_TRUE(stream_->HasPendingRetransmission());
1390 // This OnCanWrite causes [18, 27) and fin to be retransmitted. Verify fin can
1391 // be bundled with data.
renjietang41a1b412020-02-27 15:05:14 -08001392 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001393 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001394 return session_->ConsumeData(stream_->id(), 9u, 18u, FIN,
1395 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001396 }));
1397 stream_->OnCanWrite();
1398 EXPECT_FALSE(stream_->HasPendingRetransmission());
1399 // Lost [9, 18) again, but it is not considered as lost because kData2
1400 // has been acked.
1401 stream_->OnStreamFrameLost(9, 9, false);
1402 EXPECT_FALSE(stream_->HasPendingRetransmission());
1403 EXPECT_TRUE(stream_->IsStreamFrameOutstanding(27, 0, true));
1404}
1405
1406TEST_P(QuicStreamTest, CannotBundleLostFin) {
1407 Initialize();
1408
1409 // Send [0, 18) and fin.
renjietang41a1b412020-02-27 15:05:14 -08001410 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001411 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001412 stream_->WriteOrBufferData(kData1, false, nullptr);
1413 stream_->WriteOrBufferData(kData2, true, nullptr);
1414
1415 // Lost [0, 9) and fin.
1416 stream_->OnStreamFrameLost(0, 9, false);
1417 stream_->OnStreamFrameLost(18, 0, true);
1418
1419 // Retransmit lost data. Verify [0, 9) and fin are retransmitted in two
1420 // frames.
1421 InSequence s;
renjietang41a1b412020-02-27 15:05:14 -08001422 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001423 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001424 return session_->ConsumeData(stream_->id(), 9u, 0u, NO_FIN,
1425 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001426 }));
renjietang41a1b412020-02-27 15:05:14 -08001427 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001428 .WillOnce(Return(QuicConsumedData(0, true)));
1429 stream_->OnCanWrite();
1430}
1431
1432TEST_P(QuicStreamTest, MarkConnectionLevelWriteBlockedOnWindowUpdateFrame) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001433 Initialize();
1434
renjietang39979d32019-09-13 10:02:13 -07001435 // Set the config to a small value so that a newly created stream has small
1436 // send flow control window.
1437 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_->config(),
1438 100);
renjietang9bf25642019-10-10 10:21:15 -07001439 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional(
1440 session_->config(), 100);
renjietang39979d32019-09-13 10:02:13 -07001441 auto stream = new TestStream(GetNthClientInitiatedBidirectionalStreamId(
1442 GetParam().transport_version, 2),
1443 session_.get(), BIDIRECTIONAL);
1444 session_->ActivateStream(QuicWrapUnique(stream));
1445
renjietang41a1b412020-02-27 15:05:14 -08001446 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001447 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001448 EXPECT_CALL(*connection_, SendControlFrame(_))
bnc5b3c3be2019-06-25 10:37:09 -07001449 .WillOnce(Invoke(&ClearControlFrame));
vasilvvc48c8712019-03-11 13:38:16 -07001450 std::string data(1024, '.');
renjietang39979d32019-09-13 10:02:13 -07001451 stream->WriteOrBufferData(data, false, nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001452 EXPECT_FALSE(HasWriteBlockedStreams());
1453
1454 QuicWindowUpdateFrame window_update(kInvalidControlFrameId, stream_->id(),
1455 1234);
1456
renjietang39979d32019-09-13 10:02:13 -07001457 stream->OnWindowUpdateFrame(window_update);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001458 // Verify stream is marked connection level write blocked.
1459 EXPECT_TRUE(HasWriteBlockedStreams());
renjietang39979d32019-09-13 10:02:13 -07001460 EXPECT_TRUE(stream->HasBufferedData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001461}
1462
1463// Regression test for b/73282665.
1464TEST_P(QuicStreamTest,
1465 MarkConnectionLevelWriteBlockedOnWindowUpdateFrameWithNoBufferedData) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001466 Initialize();
1467
renjietang39979d32019-09-13 10:02:13 -07001468 // Set the config to a small value so that a newly created stream has small
1469 // send flow control window.
1470 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_->config(),
1471 100);
renjietang9bf25642019-10-10 10:21:15 -07001472 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesIncomingBidirectional(
1473 session_->config(), 100);
renjietang39979d32019-09-13 10:02:13 -07001474 auto stream = new TestStream(GetNthClientInitiatedBidirectionalStreamId(
1475 GetParam().transport_version, 2),
1476 session_.get(), BIDIRECTIONAL);
1477 session_->ActivateStream(QuicWrapUnique(stream));
1478
1479 std::string data(100, '.');
renjietang41a1b412020-02-27 15:05:14 -08001480 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -08001481 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001482 EXPECT_CALL(*connection_, SendControlFrame(_))
bnc5b3c3be2019-06-25 10:37:09 -07001483 .WillOnce(Invoke(&ClearControlFrame));
renjietang39979d32019-09-13 10:02:13 -07001484 stream->WriteOrBufferData(data, false, nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001485 EXPECT_FALSE(HasWriteBlockedStreams());
1486
1487 QuicWindowUpdateFrame window_update(kInvalidControlFrameId, stream_->id(),
1488 120);
renjietang39979d32019-09-13 10:02:13 -07001489 stream->OnWindowUpdateFrame(window_update);
1490 EXPECT_FALSE(stream->HasBufferedData());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001491 // Verify stream is marked as blocked although there is no buffered data.
1492 EXPECT_TRUE(HasWriteBlockedStreams());
1493}
1494
1495TEST_P(QuicStreamTest, RetransmitStreamData) {
1496 Initialize();
1497 InSequence s;
1498
1499 // Send [0, 18) with fin.
renjietang41a1b412020-02-27 15:05:14 -08001500 EXPECT_CALL(*session_, WritevData(stream_->id(), _, _, _, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001501 .Times(2)
renjietang7c239172020-02-21 13:50:39 -08001502 .WillRepeatedly(Invoke(session_.get(), &MockQuicSession::ConsumeData));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001503 stream_->WriteOrBufferData(kData1, false, nullptr);
1504 stream_->WriteOrBufferData(kData1, true, nullptr);
1505 // Ack [10, 13).
1506 QuicByteCount newly_acked_length = 0;
1507 stream_->OnStreamFrameAcked(10, 3, false, QuicTime::Delta::Zero(),
QUICHE team2f5f30b2020-02-18 08:52:28 -08001508 QuicTime::Zero(), &newly_acked_length);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001509 EXPECT_EQ(3u, newly_acked_length);
1510 // Retransmit [0, 18) with fin, and only [0, 8) is consumed.
renjietang41a1b412020-02-27 15:05:14 -08001511 EXPECT_CALL(*session_, WritevData(stream_->id(), 10, 0, NO_FIN, _, _))
QUICHE teama6ef0a62019-03-07 20:34:33 -05001512 .WillOnce(InvokeWithoutArgs([this]() {
renjietang4d992bf2020-03-03 13:01:55 -08001513 return session_->ConsumeData(stream_->id(), 8, 0u, NO_FIN,
1514 NOT_RETRANSMISSION, QuicheNullOpt);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001515 }));
renjietang4d992bf2020-03-03 13:01:55 -08001516 EXPECT_FALSE(stream_->RetransmitStreamData(0, 18, true, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001517
1518 // Retransmit [0, 18) with fin, and all is consumed.
renjietang41a1b412020-02-27 15:05:14 -08001519 EXPECT_CALL(*session_, WritevData(stream_->id(), 10, 0, NO_FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001520 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang41a1b412020-02-27 15:05:14 -08001521 EXPECT_CALL(*session_, WritevData(stream_->id(), 5, 13, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001522 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang4d992bf2020-03-03 13:01:55 -08001523 EXPECT_TRUE(stream_->RetransmitStreamData(0, 18, true, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001524
1525 // Retransmit [0, 8) with fin, and all is consumed.
renjietang41a1b412020-02-27 15:05:14 -08001526 EXPECT_CALL(*session_, WritevData(stream_->id(), 8, 0, NO_FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001527 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang41a1b412020-02-27 15:05:14 -08001528 EXPECT_CALL(*session_, WritevData(stream_->id(), 0, 18, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001529 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang4d992bf2020-03-03 13:01:55 -08001530 EXPECT_TRUE(stream_->RetransmitStreamData(0, 8, true, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001531}
1532
1533TEST_P(QuicStreamTest, ResetStreamOnTtlExpiresRetransmitLostData) {
1534 Initialize();
1535
renjietang41a1b412020-02-27 15:05:14 -08001536 EXPECT_CALL(*session_, WritevData(stream_->id(), 200, 0, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001537 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
vasilvvc48c8712019-03-11 13:38:16 -07001538 std::string body(200, 'a');
QUICHE teama6ef0a62019-03-07 20:34:33 -05001539 stream_->WriteOrBufferData(body, true, nullptr);
1540
1541 // Set TTL to be 1 s.
1542 QuicTime::Delta ttl = QuicTime::Delta::FromSeconds(1);
1543 ASSERT_TRUE(stream_->MaybeSetTtl(ttl));
1544 // Verify data gets retransmitted because TTL does not expire.
renjietang41a1b412020-02-27 15:05:14 -08001545 EXPECT_CALL(*session_, WritevData(stream_->id(), 100, 0, NO_FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001546 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
renjietang4d992bf2020-03-03 13:01:55 -08001547 EXPECT_TRUE(stream_->RetransmitStreamData(0, 100, false, PTO_RETRANSMISSION));
QUICHE teama6ef0a62019-03-07 20:34:33 -05001548 stream_->OnStreamFrameLost(100, 100, true);
1549 EXPECT_TRUE(stream_->HasPendingRetransmission());
1550
1551 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
1552 // Verify stream gets reset because TTL expires.
1553 EXPECT_CALL(*session_, SendRstStream(_, QUIC_STREAM_TTL_EXPIRED, _)).Times(1);
1554 stream_->OnCanWrite();
1555}
1556
1557TEST_P(QuicStreamTest, ResetStreamOnTtlExpiresEarlyRetransmitData) {
1558 Initialize();
1559
renjietang41a1b412020-02-27 15:05:14 -08001560 EXPECT_CALL(*session_, WritevData(stream_->id(), 200, 0, FIN, _, _))
renjietang7c239172020-02-21 13:50:39 -08001561 .WillOnce(Invoke(session_.get(), &MockQuicSession::ConsumeData));
vasilvvc48c8712019-03-11 13:38:16 -07001562 std::string body(200, 'a');
QUICHE teama6ef0a62019-03-07 20:34:33 -05001563 stream_->WriteOrBufferData(body, true, nullptr);
1564
1565 // Set TTL to be 1 s.
1566 QuicTime::Delta ttl = QuicTime::Delta::FromSeconds(1);
1567 ASSERT_TRUE(stream_->MaybeSetTtl(ttl));
1568
1569 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
1570 // Verify stream gets reset because TTL expires.
1571 EXPECT_CALL(*session_, SendRstStream(_, QUIC_STREAM_TTL_EXPIRED, _)).Times(1);
renjietang4d992bf2020-03-03 13:01:55 -08001572 stream_->RetransmitStreamData(0, 100, false, PTO_RETRANSMISSION);
QUICHE teama6ef0a62019-03-07 20:34:33 -05001573}
1574
1575// Test that QuicStream::StopSending A) is a no-op if the connection is not in
1576// version 99, B) that it properly invokes QuicSession::StopSending, and C) that
1577// the correct data is passed along, including getting the stream ID.
renjietang9bf25642019-10-10 10:21:15 -07001578TEST_P(QuicStreamTest, CheckStopSending) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001579 Initialize();
1580 const int kStopSendingCode = 123;
1581 // These must start as false.
bncc7d9e0c2019-04-16 10:22:15 -07001582 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001583 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
1584 // Expect to actually see a stop sending if and only if we are in version 99.
fkastenholz305e1732019-06-18 05:01:22 -07001585 if (VersionHasIetfQuicFrames(connection_->transport_version())) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001586 EXPECT_CALL(*session_, SendStopSending(kStopSendingCode, stream_->id()))
1587 .Times(1);
1588 } else {
1589 EXPECT_CALL(*session_, SendStopSending(_, _)).Times(0);
1590 }
1591 stream_->SendStopSending(kStopSendingCode);
1592 // Sending a STOP_SENDING does not actually close the local stream.
1593 // Our implementation waits for the responding RESET_STREAM to effect the
1594 // closes. Therefore, read- and write-side closes should both be false.
bncc7d9e0c2019-04-16 10:22:15 -07001595 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001596 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
1597}
1598
1599// Test that OnStreamReset does one-way (read) closes if version 99, two way
1600// (read and write) if not version 99.
1601TEST_P(QuicStreamTest, OnStreamResetReadOrReadWrite) {
1602 Initialize();
bncc7d9e0c2019-04-16 10:22:15 -07001603 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001604 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
1605
1606 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
1607 QUIC_STREAM_CANCELLED, 1234);
1608 stream_->OnStreamReset(rst_frame);
fkastenholz305e1732019-06-18 05:01:22 -07001609 if (VersionHasIetfQuicFrames(connection_->transport_version())) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001610 // Version 99/IETF QUIC should close just the read side.
1611 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
bncc7d9e0c2019-04-16 10:22:15 -07001612 EXPECT_FALSE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001613 } else {
1614 // Google QUIC should close both sides of the stream.
bncc7d9e0c2019-04-16 10:22:15 -07001615 EXPECT_TRUE(stream_->write_side_closed());
QUICHE teama6ef0a62019-03-07 20:34:33 -05001616 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
1617 }
1618}
1619
renjietang28c04b72019-07-01 15:08:09 -07001620TEST_P(QuicStreamTest, WindowUpdateForReadOnlyStream) {
renjietang28c04b72019-07-01 15:08:09 -07001621 Initialize();
1622
1623 QuicStreamId stream_id = QuicUtils::GetFirstUnidirectionalStreamId(
1624 connection_->transport_version(), Perspective::IS_CLIENT);
1625 TestStream stream(stream_id, session_.get(), READ_UNIDIRECTIONAL);
1626 QuicWindowUpdateFrame window_update_frame(kInvalidControlFrameId, stream_id,
1627 0);
1628 EXPECT_CALL(
1629 *connection_,
1630 CloseConnection(
1631 QUIC_WINDOW_UPDATE_RECEIVED_ON_READ_UNIDIRECTIONAL_STREAM,
1632 "WindowUpdateFrame received on READ_UNIDIRECTIONAL stream.", _));
1633 stream.OnWindowUpdateFrame(window_update_frame);
1634}
1635
renjietang15afba32019-10-23 14:32:35 -07001636TEST_P(QuicStreamTest, RstStreamFrameChangesCloseOffset) {
renjietang15afba32019-10-23 14:32:35 -07001637 Initialize();
1638
1639 QuicStreamFrame stream_frame(stream_->id(), true, 0, "abc");
renjietangb38e6352019-10-24 09:38:20 -07001640 EXPECT_CALL(*stream_, OnDataAvailable());
renjietang15afba32019-10-23 14:32:35 -07001641 stream_->OnStreamFrame(stream_frame);
1642 QuicRstStreamFrame rst(kInvalidControlFrameId, stream_->id(),
1643 QUIC_STREAM_CANCELLED, 0u);
1644
1645 EXPECT_CALL(*connection_, CloseConnection(QUIC_STREAM_MULTIPLE_OFFSET, _, _));
1646 stream_->OnStreamReset(rst);
1647}
1648
QUICHE teama6ef0a62019-03-07 20:34:33 -05001649} // namespace
1650} // namespace test
1651} // namespace quic