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