Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: net/quic/reliable_quic_stream_test.cc

Issue 1784903003: Remove FEC from send path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@114770052
Patch Set: Restore accidentally removed OnRttChanged call Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/reliable_quic_stream.cc ('k') | net/quic/test_tools/quic_connection_peer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/reliable_quic_stream.h" 5 #include "net/quic/reliable_quic_stream.h"
6 6
7 #include "net/quic/quic_connection.h" 7 #include "net/quic/quic_connection.h"
8 #include "net/quic/quic_flags.h" 8 #include "net/quic/quic_flags.h"
9 #include "net/quic/quic_utils.h" 9 #include "net/quic/quic_utils.h"
10 #include "net/quic/quic_write_blocked_list.h" 10 #include "net/quic/quic_write_blocked_list.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool HasWriteBlockedStreams() { 134 bool HasWriteBlockedStreams() {
135 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() || 135 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() ||
136 write_blocked_list_->HasWriteBlockedDataStreams(); 136 write_blocked_list_->HasWriteBlockedDataStreams();
137 } 137 }
138 138
139 QuicConsumedData CloseStreamOnWriteError( 139 QuicConsumedData CloseStreamOnWriteError(
140 QuicStreamId id, 140 QuicStreamId id,
141 QuicIOVector /*iov*/, 141 QuicIOVector /*iov*/,
142 QuicStreamOffset /*offset*/, 142 QuicStreamOffset /*offset*/,
143 bool /*fin*/, 143 bool /*fin*/,
144 FecProtection /*fec_protection*/,
145 QuicAckListenerInterface* /*ack_notifier_delegate*/) { 144 QuicAckListenerInterface* /*ack_notifier_delegate*/) {
146 session_->CloseStream(id); 145 session_->CloseStream(id);
147 return QuicConsumedData(1, false); 146 return QuicConsumedData(1, false);
148 } 147 }
149 148
150 protected: 149 protected:
151 MockConnectionHelper helper_; 150 MockConnectionHelper helper_;
152 MockConnection* connection_; 151 MockConnection* connection_;
153 scoped_ptr<MockQuicSpdySession> session_; 152 scoped_ptr<MockQuicSpdySession> session_;
154 TestStream* stream_; 153 TestStream* stream_;
155 SpdyHeaderBlock headers_; 154 SpdyHeaderBlock headers_;
156 QuicWriteBlockedList* write_blocked_list_; 155 QuicWriteBlockedList* write_blocked_list_;
157 uint32_t initial_flow_control_window_bytes_; 156 uint32_t initial_flow_control_window_bytes_;
158 QuicTime::Delta zero_; 157 QuicTime::Delta zero_;
159 QuicVersionVector supported_versions_; 158 QuicVersionVector supported_versions_;
160 const QuicStreamId kTestStreamId = 5u; 159 const QuicStreamId kTestStreamId = 5u;
161 }; 160 };
162 161
163 TEST_F(ReliableQuicStreamTest, WriteAllData) { 162 TEST_F(ReliableQuicStreamTest, WriteAllData) {
164 Initialize(kShouldProcessData); 163 Initialize(kShouldProcessData);
165 164
166 size_t length = 165 size_t length =
167 1 + QuicPacketCreator::StreamFramePacketOverhead( 166 1 + QuicPacketCreator::StreamFramePacketOverhead(
168 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, 167 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId,
169 PACKET_6BYTE_PACKET_NUMBER, 0u, NOT_IN_FEC_GROUP); 168 PACKET_6BYTE_PACKET_NUMBER, 0u, NOT_IN_FEC_GROUP);
170 connection_->SetMaxPacketLength(length); 169 connection_->SetMaxPacketLength(length);
171 170
172 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 171 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
173 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 172 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
174 stream_->WriteOrBufferData(kData1, false, nullptr); 173 stream_->WriteOrBufferData(kData1, false, nullptr);
175 EXPECT_FALSE(HasWriteBlockedStreams()); 174 EXPECT_FALSE(HasWriteBlockedStreams());
176 } 175 }
177 176
178 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { 177 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) {
179 Initialize(kShouldProcessData); 178 Initialize(kShouldProcessData);
180 179
181 // Write no data and no fin. If we consume nothing we should not be write 180 // Write no data and no fin. If we consume nothing we should not be write
182 // blocked. 181 // blocked.
183 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false, nullptr), ""); 182 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false, nullptr), "");
184 EXPECT_FALSE(HasWriteBlockedStreams()); 183 EXPECT_FALSE(HasWriteBlockedStreams());
185 } 184 }
186 185
187 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { 186 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) {
188 Initialize(kShouldProcessData); 187 Initialize(kShouldProcessData);
189 188
190 // Write some data and no fin. If we consume some but not all of the data, 189 // Write some data and no fin. If we consume some but not all of the data,
191 // we should be write blocked a not all the data was consumed. 190 // we should be write blocked a not all the data was consumed.
192 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 191 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
193 .WillOnce(Return(QuicConsumedData(1, false))); 192 .WillOnce(Return(QuicConsumedData(1, false)));
194 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 193 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr);
195 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 194 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
196 EXPECT_EQ(1u, stream_->queued_data_bytes()); 195 EXPECT_EQ(1u, stream_->queued_data_bytes());
197 } 196 }
198 197
199 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { 198 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) {
200 Initialize(kShouldProcessData); 199 Initialize(kShouldProcessData);
201 200
202 // Write some data and no fin. If we consume all the data but not the fin, 201 // Write some data and no fin. If we consume all the data but not the fin,
203 // we should be write blocked because the fin was not consumed. 202 // we should be write blocked because the fin was not consumed.
204 // (This should never actually happen as the fin should be sent out with the 203 // (This should never actually happen as the fin should be sent out with the
205 // last data) 204 // last data)
206 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 205 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
207 .WillOnce(Return(QuicConsumedData(2, false))); 206 .WillOnce(Return(QuicConsumedData(2, false)));
208 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 207 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
209 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 208 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
210 } 209 }
211 210
212 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { 211 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) {
213 Initialize(kShouldProcessData); 212 Initialize(kShouldProcessData);
214 213
215 // Write no data and a fin. If we consume nothing we should be write blocked, 214 // Write no data and a fin. If we consume nothing we should be write blocked,
216 // as the fin was not consumed. 215 // as the fin was not consumed.
217 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 216 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
218 .WillOnce(Return(QuicConsumedData(0, false))); 217 .WillOnce(Return(QuicConsumedData(0, false)));
219 stream_->WriteOrBufferData(StringPiece(), true, nullptr); 218 stream_->WriteOrBufferData(StringPiece(), true, nullptr);
220 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 219 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
221 } 220 }
222 221
223 TEST_F(ReliableQuicStreamTest, CloseOnPartialWrite) { 222 TEST_F(ReliableQuicStreamTest, CloseOnPartialWrite) {
224 Initialize(kShouldProcessData); 223 Initialize(kShouldProcessData);
225 224
226 // Write some data and no fin. However, while writing the data 225 // Write some data and no fin. However, while writing the data
227 // close the stream and verify that MarkConnectionLevelWriteBlocked does not 226 // close the stream and verify that MarkConnectionLevelWriteBlocked does not
228 // crash with an unknown stream. 227 // crash with an unknown stream.
229 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 228 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
230 .WillOnce(Invoke(this, &ReliableQuicStreamTest::CloseStreamOnWriteError)); 229 .WillOnce(Invoke(this, &ReliableQuicStreamTest::CloseStreamOnWriteError));
231 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 230 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr);
232 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams()); 231 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams());
233 } 232 }
234 233
235 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { 234 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) {
236 Initialize(kShouldProcessData); 235 Initialize(kShouldProcessData);
237 236
238 EXPECT_FALSE(HasWriteBlockedStreams()); 237 EXPECT_FALSE(HasWriteBlockedStreams());
239 size_t length = 238 size_t length =
240 1 + QuicPacketCreator::StreamFramePacketOverhead( 239 1 + QuicPacketCreator::StreamFramePacketOverhead(
241 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, 240 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId,
242 PACKET_6BYTE_PACKET_NUMBER, 0u, NOT_IN_FEC_GROUP); 241 PACKET_6BYTE_PACKET_NUMBER, 0u, NOT_IN_FEC_GROUP);
243 connection_->SetMaxPacketLength(length); 242 connection_->SetMaxPacketLength(length);
244 243
245 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 244 EXPECT_CALL(*session_, WritevData(_, _, _, _, _))
246 .WillOnce(Return(QuicConsumedData(kDataLen - 1, false))); 245 .WillOnce(Return(QuicConsumedData(kDataLen - 1, false)));
247 stream_->WriteOrBufferData(kData1, false, nullptr); 246 stream_->WriteOrBufferData(kData1, false, nullptr);
248 EXPECT_TRUE(HasWriteBlockedStreams()); 247 EXPECT_TRUE(HasWriteBlockedStreams());
249 248
250 // Queue a bytes_consumed write. 249 // Queue a bytes_consumed write.
251 stream_->WriteOrBufferData(kData2, false, nullptr); 250 stream_->WriteOrBufferData(kData2, false, nullptr);
252 251
253 // Make sure we get the tail of the first write followed by the bytes_consumed 252 // Make sure we get the tail of the first write followed by the bytes_consumed
254 InSequence s; 253 InSequence s;
255 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 254 EXPECT_CALL(*session_, WritevData(_, _, _, _, _))
256 .WillOnce(Return(QuicConsumedData(1, false))); 255 .WillOnce(Return(QuicConsumedData(1, false)));
257 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 256 EXPECT_CALL(*session_, WritevData(_, _, _, _, _))
258 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); 257 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false)));
259 stream_->OnCanWrite(); 258 stream_->OnCanWrite();
260 259
261 // And finally the end of the bytes_consumed. 260 // And finally the end of the bytes_consumed.
262 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 261 EXPECT_CALL(*session_, WritevData(_, _, _, _, _))
263 .WillOnce(Return(QuicConsumedData(2, true))); 262 .WillOnce(Return(QuicConsumedData(2, true)));
264 stream_->OnCanWrite(); 263 stream_->OnCanWrite();
265 } 264 }
266
267 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithFecProtectAlways) {
268 Initialize(kShouldProcessData);
269
270 // Set FEC policy on stream.
271 ReliableQuicStreamPeer::SetFecPolicy(stream_, FEC_PROTECT_ALWAYS);
272
273 EXPECT_FALSE(HasWriteBlockedStreams());
274 size_t length =
275 1 + QuicPacketCreator::StreamFramePacketOverhead(
276 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId,
277 PACKET_6BYTE_PACKET_NUMBER, 0u, IN_FEC_GROUP);
278 connection_->SetMaxPacketLength(length);
279
280 // Write first data onto stream, which will cause one session write.
281 EXPECT_CALL(*session_, WritevData(_, _, _, _, MUST_FEC_PROTECT, _))
282 .WillOnce(Return(QuicConsumedData(kDataLen - 1, false)));
283 stream_->WriteOrBufferData(kData1, false, nullptr);
284 EXPECT_TRUE(HasWriteBlockedStreams());
285
286 // Queue a bytes_consumed write.
287 stream_->WriteOrBufferData(kData2, false, nullptr);
288
289 // Make sure we get the tail of the first write followed by the bytes_consumed
290 InSequence s;
291 EXPECT_CALL(*session_, WritevData(_, _, _, _, MUST_FEC_PROTECT, _))
292 .WillOnce(Return(QuicConsumedData(1, false)));
293 EXPECT_CALL(*session_, WritevData(_, _, _, _, MUST_FEC_PROTECT, _))
294 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false)));
295 stream_->OnCanWrite();
296
297 // And finally the end of the bytes_consumed.
298 EXPECT_CALL(*session_, WritevData(_, _, _, _, MUST_FEC_PROTECT, _))
299 .WillOnce(Return(QuicConsumedData(2, true)));
300 stream_->OnCanWrite();
301 }
302
303 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithFecProtectOptional) {
304 Initialize(kShouldProcessData);
305
306 // Set FEC policy on stream.
307 ReliableQuicStreamPeer::SetFecPolicy(stream_, FEC_PROTECT_OPTIONAL);
308
309 EXPECT_FALSE(HasWriteBlockedStreams());
310 size_t length =
311 1 + QuicPacketCreator::StreamFramePacketOverhead(
312 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId,
313 PACKET_6BYTE_PACKET_NUMBER, 0u, NOT_IN_FEC_GROUP);
314 connection_->SetMaxPacketLength(length);
315
316 // Write first data onto stream, which will cause one session write.
317 EXPECT_CALL(*session_, WritevData(_, _, _, _, MAY_FEC_PROTECT, _))
318 .WillOnce(Return(QuicConsumedData(kDataLen - 1, false)));
319 stream_->WriteOrBufferData(kData1, false, nullptr);
320 EXPECT_TRUE(HasWriteBlockedStreams());
321
322 // Queue a bytes_consumed write.
323 stream_->WriteOrBufferData(kData2, false, nullptr);
324
325 // Make sure we get the tail of the first write followed by the bytes_consumed
326 InSequence s;
327 EXPECT_CALL(*session_, WritevData(_, _, _, _, MAY_FEC_PROTECT, _))
328 .WillOnce(Return(QuicConsumedData(1, false)));
329 EXPECT_CALL(*session_, WritevData(_, _, _, _, MAY_FEC_PROTECT, _))
330 .WillOnce(Return(QuicConsumedData(kDataLen - 2, false)));
331 stream_->OnCanWrite();
332
333 // And finally the end of the bytes_consumed.
334 EXPECT_CALL(*session_, WritevData(_, _, _, _, MAY_FEC_PROTECT, _))
335 .WillOnce(Return(QuicConsumedData(2, true)));
336 stream_->OnCanWrite();
337 }
338 265
339 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) { 266 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) {
340 Initialize(kShouldProcessData); 267 Initialize(kShouldProcessData);
341 268
342 ReliableQuicStreamPeer::CloseReadSide(stream_); 269 ReliableQuicStreamPeer::CloseReadSide(stream_);
343 stream_->CloseWriteSide(); 270 stream_->CloseWriteSide();
344 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); 271 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
345 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); 272 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error());
346 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, 273 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR,
347 ConnectionCloseSource::FROM_SELF); 274 ConnectionCloseSource::FROM_SELF);
348 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); 275 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
349 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); 276 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error());
350 } 277 }
351 278
352 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) { 279 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) {
353 // For flow control accounting, a stream must send either a FIN or a RST frame 280 // For flow control accounting, a stream must send either a FIN or a RST frame
354 // before termination. 281 // before termination.
355 // Test that if no FIN has been sent, we send a RST. 282 // Test that if no FIN has been sent, we send a RST.
356 283
357 Initialize(kShouldProcessData); 284 Initialize(kShouldProcessData);
358 EXPECT_FALSE(fin_sent()); 285 EXPECT_FALSE(fin_sent());
359 EXPECT_FALSE(rst_sent()); 286 EXPECT_FALSE(rst_sent());
360 287
361 // Write some data, with no FIN. 288 // Write some data, with no FIN.
362 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 289 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
363 .WillOnce(Return(QuicConsumedData(1, false))); 290 .WillOnce(Return(QuicConsumedData(1, false)));
364 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, nullptr); 291 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, nullptr);
365 EXPECT_FALSE(fin_sent()); 292 EXPECT_FALSE(fin_sent());
366 EXPECT_FALSE(rst_sent()); 293 EXPECT_FALSE(rst_sent());
367 294
368 // Now close the stream, and expect that we send a RST. 295 // Now close the stream, and expect that we send a RST.
369 EXPECT_CALL(*session_, SendRstStream(_, _, _)); 296 EXPECT_CALL(*session_, SendRstStream(_, _, _));
370 stream_->OnClose(); 297 stream_->OnClose();
371 EXPECT_FALSE(fin_sent()); 298 EXPECT_FALSE(fin_sent());
372 EXPECT_TRUE(rst_sent()); 299 EXPECT_TRUE(rst_sent());
373 } 300 }
374 301
375 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) { 302 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) {
376 // For flow control accounting, a stream must send either a FIN or a RST frame 303 // For flow control accounting, a stream must send either a FIN or a RST frame
377 // before termination. 304 // before termination.
378 // Test that if a FIN has been sent, we don't also send a RST. 305 // Test that if a FIN has been sent, we don't also send a RST.
379 306
380 Initialize(kShouldProcessData); 307 Initialize(kShouldProcessData);
381 EXPECT_FALSE(fin_sent()); 308 EXPECT_FALSE(fin_sent());
382 EXPECT_FALSE(rst_sent()); 309 EXPECT_FALSE(rst_sent());
383 310
384 // Write some data, with FIN. 311 // Write some data, with FIN.
385 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 312 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
386 .WillOnce(Return(QuicConsumedData(1, true))); 313 .WillOnce(Return(QuicConsumedData(1, true)));
387 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, nullptr); 314 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, nullptr);
388 EXPECT_TRUE(fin_sent()); 315 EXPECT_TRUE(fin_sent());
389 EXPECT_FALSE(rst_sent()); 316 EXPECT_FALSE(rst_sent());
390 317
391 // Now close the stream, and expect that we do not send a RST. 318 // Now close the stream, and expect that we do not send a RST.
392 stream_->OnClose(); 319 stream_->OnClose();
393 EXPECT_TRUE(fin_sent()); 320 EXPECT_TRUE(fin_sent());
394 EXPECT_FALSE(rst_sent()); 321 EXPECT_FALSE(rst_sent());
395 } 322 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 const int kFirstWriteSize = 100; 396 const int kFirstWriteSize = 100;
470 const int kSecondWriteSize = 50; 397 const int kSecondWriteSize = 50;
471 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; 398 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize;
472 399
473 // Set a large flow control send window so this doesn't interfere with test. 400 // Set a large flow control send window so this doesn't interfere with test.
474 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 401 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
475 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 402 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
476 403
477 scoped_refptr<QuicAckListenerInterface> ack_listener; 404 scoped_refptr<QuicAckListenerInterface> ack_listener;
478 405
479 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 406 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
480 .WillOnce(DoAll( 407 .WillOnce(DoAll(
481 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &ack_listener))), 408 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &ack_listener))),
482 Return(QuicConsumedData(kFirstWriteSize, false)))); 409 Return(QuicConsumedData(kFirstWriteSize, false))));
483 stream_->WriteOrBufferData(kData, false, delegate.get()); 410 stream_->WriteOrBufferData(kData, false, delegate.get());
484 EXPECT_TRUE(HasWriteBlockedStreams()); 411 EXPECT_TRUE(HasWriteBlockedStreams());
485 412
486 EXPECT_CALL(*session_, 413 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, ack_listener.get()))
487 WritevData(kTestStreamId, _, _, _, _, ack_listener.get()))
488 .WillOnce(Return(QuicConsumedData(kSecondWriteSize, false))); 414 .WillOnce(Return(QuicConsumedData(kSecondWriteSize, false)));
489 stream_->OnCanWrite(); 415 stream_->OnCanWrite();
490 416
491 // No ack expected for an empty write. 417 // No ack expected for an empty write.
492 EXPECT_CALL(*session_, 418 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, ack_listener.get()))
493 WritevData(kTestStreamId, _, _, _, _, ack_listener.get()))
494 .WillOnce(Return(QuicConsumedData(0, false))); 419 .WillOnce(Return(QuicConsumedData(0, false)));
495 stream_->OnCanWrite(); 420 stream_->OnCanWrite();
496 421
497 EXPECT_CALL(*session_, 422 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, ack_listener.get()))
498 WritevData(kTestStreamId, _, _, _, _, ack_listener.get()))
499 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false))); 423 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false)));
500 stream_->OnCanWrite(); 424 stream_->OnCanWrite();
501 } 425 }
502 426
503 // Verify delegate behavior when packets are acked before the WritevData call 427 // Verify delegate behavior when packets are acked before the WritevData call
504 // that sends out the last byte. 428 // that sends out the last byte.
505 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { 429 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) {
506 Initialize(kShouldProcessData); 430 Initialize(kShouldProcessData);
507 431
508 scoped_refptr<MockAckListener> ack_listener(new StrictMock<MockAckListener>); 432 scoped_refptr<MockAckListener> ack_listener(new StrictMock<MockAckListener>);
509 433
510 const int kDataSize = 16 * 1024; 434 const int kDataSize = 16 * 1024;
511 const string kData(kDataSize, 'a'); 435 const string kData(kDataSize, 'a');
512 436
513 const int kInitialWriteSize = 100; 437 const int kInitialWriteSize = 100;
514 438
515 // Set a large flow control send window so this doesn't interfere with test. 439 // Set a large flow control send window so this doesn't interfere with test.
516 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 440 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
517 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); 441 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
518 442
519 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 443 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
520 444
521 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 445 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
522 .WillOnce(DoAll( 446 .WillOnce(DoAll(
523 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 447 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
524 Return(QuicConsumedData(kInitialWriteSize, false)))); 448 Return(QuicConsumedData(kInitialWriteSize, false))));
525 stream_->WriteOrBufferData(kData, false, ack_listener.get()); 449 stream_->WriteOrBufferData(kData, false, ack_listener.get());
526 EXPECT_TRUE(HasWriteBlockedStreams()); 450 EXPECT_TRUE(HasWriteBlockedStreams());
527 451
528 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 452 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
529 .WillOnce(DoAll( 453 .WillOnce(DoAll(
530 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 454 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
531 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); 455 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false))));
532 stream_->OnCanWrite(); 456 stream_->OnCanWrite();
533 } 457 }
534 458
535 // Verify delegate behavior when WriteOrBufferData does not buffer. 459 // Verify delegate behavior when WriteOrBufferData does not buffer.
536 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { 460 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) {
537 Initialize(kShouldProcessData); 461 Initialize(kShouldProcessData);
538 462
539 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 463 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
540 464
541 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 465 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
542 466
543 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 467 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
544 .WillOnce(DoAll( 468 .WillOnce(DoAll(
545 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 469 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
546 Return(QuicConsumedData(kDataLen, true)))); 470 Return(QuicConsumedData(kDataLen, true))));
547 stream_->WriteOrBufferData(kData1, true, delegate.get()); 471 stream_->WriteOrBufferData(kData1, true, delegate.get());
548 EXPECT_FALSE(HasWriteBlockedStreams()); 472 EXPECT_FALSE(HasWriteBlockedStreams());
549 } 473 }
550 474
551 // Verify delegate behavior when WriteOrBufferData buffers all the data. 475 // Verify delegate behavior when WriteOrBufferData buffers all the data.
552 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { 476 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) {
553 Initialize(kShouldProcessData); 477 Initialize(kShouldProcessData);
554 478
555 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 479 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
556 480
557 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 481 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
558 482
559 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 483 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
560 .WillOnce(Return(QuicConsumedData(0, false))); 484 .WillOnce(Return(QuicConsumedData(0, false)));
561 stream_->WriteOrBufferData(kData1, true, delegate.get()); 485 stream_->WriteOrBufferData(kData1, true, delegate.get());
562 EXPECT_TRUE(HasWriteBlockedStreams()); 486 EXPECT_TRUE(HasWriteBlockedStreams());
563 487
564 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 488 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
565 .WillOnce(DoAll( 489 .WillOnce(DoAll(
566 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 490 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
567 Return(QuicConsumedData(kDataLen, true)))); 491 Return(QuicConsumedData(kDataLen, true))));
568 stream_->OnCanWrite(); 492 stream_->OnCanWrite();
569 } 493 }
570 494
571 // Verify delegate behavior when WriteOrBufferData when the FIN is 495 // Verify delegate behavior when WriteOrBufferData when the FIN is
572 // sent out in a different packet. 496 // sent out in a different packet.
573 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { 497 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) {
574 Initialize(kShouldProcessData); 498 Initialize(kShouldProcessData);
575 499
576 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>); 500 scoped_refptr<MockAckListener> delegate(new StrictMock<MockAckListener>);
577 501
578 scoped_refptr<QuicAckListenerInterface> proxy_delegate; 502 scoped_refptr<QuicAckListenerInterface> proxy_delegate;
579 503
580 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 504 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
581 .WillOnce(DoAll( 505 .WillOnce(DoAll(
582 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 506 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
583 Return(QuicConsumedData(kDataLen, false)))); 507 Return(QuicConsumedData(kDataLen, false))));
584 stream_->WriteOrBufferData(kData1, true, delegate.get()); 508 stream_->WriteOrBufferData(kData1, true, delegate.get());
585 EXPECT_TRUE(HasWriteBlockedStreams()); 509 EXPECT_TRUE(HasWriteBlockedStreams());
586 510
587 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 511 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
588 .WillOnce(DoAll( 512 .WillOnce(DoAll(
589 WithArgs<5>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))), 513 WithArgs<4>(Invoke(CreateFunctor(SaveAckListener, &proxy_delegate))),
590 Return(QuicConsumedData(0, true)))); 514 Return(QuicConsumedData(0, true))));
591 stream_->OnCanWrite(); 515 stream_->OnCanWrite();
592 } 516 }
593 517
594 // Verify that when we receive a packet which violates flow control (i.e. sends 518 // Verify that when we receive a packet which violates flow control (i.e. sends
595 // too much data on the stream) that the stream sequencer never sees this frame, 519 // too much data on the stream) that the stream sequencer never sees this frame,
596 // as we check for violation and close the connection early. 520 // as we check for violation and close the connection early.
597 TEST_F(ReliableQuicStreamTest, 521 TEST_F(ReliableQuicStreamTest,
598 StreamSequencerNeverSeesPacketsViolatingFlowControl) { 522 StreamSequencerNeverSeesPacketsViolatingFlowControl) {
599 Initialize(kShouldProcessData); 523 Initialize(kShouldProcessData);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 StringPiece(".")); 595 StringPiece("."));
672 stream_->OnStreamFrame(stream_frame_with_fin); 596 stream_->OnStreamFrame(stream_frame_with_fin);
673 // The FIN has been received but not consumed. 597 // The FIN has been received but not consumed.
674 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 598 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
675 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); 599 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_));
676 EXPECT_FALSE(stream_->reading_stopped()); 600 EXPECT_FALSE(stream_->reading_stopped());
677 601
678 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 602 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
679 603
680 // Outgoing data with FIN. 604 // Outgoing data with FIN.
681 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 605 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
682 .WillOnce(Return(QuicConsumedData(2, true))); 606 .WillOnce(Return(QuicConsumedData(2, true)));
683 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 607 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
684 EXPECT_TRUE(stream_->write_side_closed()); 608 EXPECT_TRUE(stream_->write_side_closed());
685 609
686 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 610 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
687 ->count(kTestStreamId)); 611 ->count(kTestStreamId));
688 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 612 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
689 } 613 }
690 614
691 TEST_F(ReliableQuicStreamTest, SetDrainingOutgoingIncoming) { 615 TEST_F(ReliableQuicStreamTest, SetDrainingOutgoingIncoming) {
692 // Don't have incoming data consumed. 616 // Don't have incoming data consumed.
693 Initialize(kShouldNotProcessData); 617 Initialize(kShouldNotProcessData);
694 618
695 // Outgoing data with FIN. 619 // Outgoing data with FIN.
696 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 620 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _))
697 .WillOnce(Return(QuicConsumedData(2, true))); 621 .WillOnce(Return(QuicConsumedData(2, true)));
698 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 622 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr);
699 EXPECT_TRUE(stream_->write_side_closed()); 623 EXPECT_TRUE(stream_->write_side_closed());
700 624
701 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 625 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
702 626
703 // Incoming data with FIN. 627 // Incoming data with FIN.
704 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 628 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
705 StringPiece(".")); 629 StringPiece("."));
706 stream_->OnStreamFrame(stream_frame_with_fin); 630 stream_->OnStreamFrame(stream_frame_with_fin);
707 // The FIN has been received but not consumed. 631 // The FIN has been received but not consumed.
708 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 632 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
709 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_)); 633 EXPECT_FALSE(ReliableQuicStreamPeer::read_side_closed(stream_));
710 EXPECT_FALSE(stream_->reading_stopped()); 634 EXPECT_FALSE(stream_->reading_stopped());
711 635
712 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 636 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
713 ->count(kTestStreamId)); 637 ->count(kTestStreamId));
714 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 638 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
715 } 639 }
716 640
717 TEST_F(ReliableQuicStreamTest, FecSendPolicyReceivedConnectionOption) {
718 Initialize(kShouldProcessData);
719
720 // Test ReceivedConnectionOptions.
721 QuicConfig* config = session_->config();
722 QuicTagVector copt;
723 copt.push_back(kFSTR);
724 QuicConfigPeer::SetReceivedConnectionOptions(config, copt);
725 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream_->fec_policy());
726 stream_->SetFromConfig();
727 EXPECT_EQ(FEC_PROTECT_ALWAYS, stream_->fec_policy());
728 }
729
730 TEST_F(ReliableQuicStreamTest, EarlyResponseFinHandling) { 641 TEST_F(ReliableQuicStreamTest, EarlyResponseFinHandling) {
731 // Verify that if the server completes the response before reading the end of 642 // Verify that if the server completes the response before reading the end of
732 // the request, the received FIN is recorded. 643 // the request, the received FIN is recorded.
733 644
734 Initialize(kShouldProcessData); 645 Initialize(kShouldProcessData);
735 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); 646 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0);
736 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 647 EXPECT_CALL(*session_, WritevData(_, _, _, _, _))
737 .WillRepeatedly(Invoke(MockQuicSpdySession::ConsumeAllData)); 648 .WillRepeatedly(Invoke(MockQuicSpdySession::ConsumeAllData));
738 649
739 // Receive data for the request. 650 // Receive data for the request.
740 QuicStreamFrame frame1(stream_->id(), false, 0, StringPiece("Start")); 651 QuicStreamFrame frame1(stream_->id(), false, 0, StringPiece("Start"));
741 stream_->OnStreamFrame(frame1); 652 stream_->OnStreamFrame(frame1);
742 // When QuicSimpleServerStream sends the response, it calls 653 // When QuicSimpleServerStream sends the response, it calls
743 // ReliableQuicStream::CloseReadSide() first. 654 // ReliableQuicStream::CloseReadSide() first.
744 ReliableQuicStreamPeer::CloseReadSide(stream_); 655 ReliableQuicStreamPeer::CloseReadSide(stream_);
745 // Send data and FIN for the response. 656 // Send data and FIN for the response.
746 stream_->WriteOrBufferData(kData1, false, nullptr); 657 stream_->WriteOrBufferData(kData1, false, nullptr);
747 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream_)); 658 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream_));
748 // Receive remaining data and FIN for the request. 659 // Receive remaining data and FIN for the request.
749 QuicStreamFrame frame2(stream_->id(), true, 0, StringPiece("End")); 660 QuicStreamFrame frame2(stream_->id(), true, 0, StringPiece("End"));
750 stream_->OnStreamFrame(frame2); 661 stream_->OnStreamFrame(frame2);
751 EXPECT_TRUE(stream_->fin_received()); 662 EXPECT_TRUE(stream_->fin_received());
752 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 663 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
753 } 664 }
754 665
755 } // namespace 666 } // namespace
756 } // namespace test 667 } // namespace test
757 } // namespace net 668 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/reliable_quic_stream.cc ('k') | net/quic/test_tools/quic_connection_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698