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

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

Issue 242453002: Pull out flow control functionality from ReliableQuicStream into a new (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/reliable_quic_stream.cc ('k') | net/quic/test_tools/quic_flow_controller_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_ack_notifier.h" 7 #include "net/quic/quic_ack_notifier.h"
8 #include "net/quic/quic_connection.h" 8 #include "net/quic/quic_connection.h"
9 #include "net/quic/quic_flags.h" 9 #include "net/quic/quic_flags.h"
10 #include "net/quic/quic_utils.h" 10 #include "net/quic/quic_utils.h"
11 #include "net/quic/quic_write_blocked_list.h" 11 #include "net/quic/quic_write_blocked_list.h"
12 #include "net/quic/spdy_utils.h" 12 #include "net/quic/spdy_utils.h"
13 #include "net/quic/test_tools/quic_flow_controller_peer.h"
13 #include "net/quic/test_tools/quic_session_peer.h" 14 #include "net/quic/test_tools/quic_session_peer.h"
14 #include "net/quic/test_tools/quic_test_utils.h" 15 #include "net/quic/test_tools/quic_test_utils.h"
15 #include "net/quic/test_tools/reliable_quic_stream_peer.h" 16 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
16 #include "net/test/gtest_util.h" 17 #include "net/test/gtest_util.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gmock_mutant.h" 19 #include "testing/gmock_mutant.h"
19 20
20 using base::StringPiece; 21 using base::StringPiece;
21 using std::min; 22 using std::min;
22 using testing::_; 23 using testing::_;
(...skipping 28 matching lines...) Expand all
51 EXPECT_NE(0u, data_len); 52 EXPECT_NE(0u, data_len);
52 DVLOG(1) << "ProcessData data_len: " << data_len; 53 DVLOG(1) << "ProcessData data_len: " << data_len;
53 data_ += string(data, data_len); 54 data_ += string(data, data_len);
54 return should_process_data_ ? data_len : 0; 55 return should_process_data_ ? data_len : 0;
55 } 56 }
56 57
57 virtual QuicPriority EffectivePriority() const OVERRIDE { 58 virtual QuicPriority EffectivePriority() const OVERRIDE {
58 return QuicUtils::HighestPriority(); 59 return QuicUtils::HighestPriority();
59 } 60 }
60 61
61 virtual bool IsFlowControlEnabled() const OVERRIDE {
62 return true;
63 }
64
65 using ReliableQuicStream::WriteOrBufferData; 62 using ReliableQuicStream::WriteOrBufferData;
66 using ReliableQuicStream::CloseReadSide; 63 using ReliableQuicStream::CloseReadSide;
67 using ReliableQuicStream::CloseWriteSide; 64 using ReliableQuicStream::CloseWriteSide;
68 using ReliableQuicStream::OnClose; 65 using ReliableQuicStream::OnClose;
69 66
70 private: 67 private:
71 bool should_process_data_; 68 bool should_process_data_;
72 string data_; 69 string data_;
73 }; 70 };
74 71
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true); 311 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true);
315 set_initial_flow_control_window_bytes(1000); 312 set_initial_flow_control_window_bytes(1000);
316 313
317 Initialize(kShouldProcessData); 314 Initialize(kShouldProcessData);
318 315
319 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we 316 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we
320 // want to make sure we latch the largest offset we see. 317 // want to make sure we latch the largest offset we see.
321 318
322 // Initially should be default. 319 // Initially should be default.
323 EXPECT_EQ(initial_flow_control_window_bytes_, 320 EXPECT_EQ(initial_flow_control_window_bytes_,
324 ReliableQuicStreamPeer::SendWindowOffset(stream_.get())); 321 QuicFlowControllerPeer::SendWindowOffset(
322 stream_.get()->flow_controller()));
325 323
326 // Check a single WINDOW_UPDATE results in correct offset. 324 // Check a single WINDOW_UPDATE results in correct offset.
327 QuicWindowUpdateFrame window_update_1(stream_->id(), 1234); 325 QuicWindowUpdateFrame window_update_1(stream_->id(), 1234);
328 stream_->OnWindowUpdateFrame(window_update_1); 326 stream_->OnWindowUpdateFrame(window_update_1);
329 EXPECT_EQ(window_update_1.byte_offset, 327 EXPECT_EQ(window_update_1.byte_offset,
330 ReliableQuicStreamPeer::SendWindowOffset(stream_.get())); 328 QuicFlowControllerPeer::SendWindowOffset(
329 stream_.get()->flow_controller()));
331 330
332 // Now send a few more WINDOW_UPDATES and make sure that only the largest is 331 // Now send a few more WINDOW_UPDATES and make sure that only the largest is
333 // remembered. 332 // remembered.
334 QuicWindowUpdateFrame window_update_2(stream_->id(), 1); 333 QuicWindowUpdateFrame window_update_2(stream_->id(), 1);
335 QuicWindowUpdateFrame window_update_3(stream_->id(), 9999); 334 QuicWindowUpdateFrame window_update_3(stream_->id(), 9999);
336 QuicWindowUpdateFrame window_update_4(stream_->id(), 5678); 335 QuicWindowUpdateFrame window_update_4(stream_->id(), 5678);
337 stream_->OnWindowUpdateFrame(window_update_2); 336 stream_->OnWindowUpdateFrame(window_update_2);
338 stream_->OnWindowUpdateFrame(window_update_3); 337 stream_->OnWindowUpdateFrame(window_update_3);
339 stream_->OnWindowUpdateFrame(window_update_4); 338 stream_->OnWindowUpdateFrame(window_update_4);
340 EXPECT_EQ(window_update_3.byte_offset, 339 EXPECT_EQ(window_update_3.byte_offset,
341 ReliableQuicStreamPeer::SendWindowOffset(stream_.get())); 340 QuicFlowControllerPeer::SendWindowOffset(
341 stream_.get()->flow_controller()));
342 } 342 }
343 343
344 void SaveProxyAckNotifierDelegate( 344 void SaveProxyAckNotifierDelegate(
345 scoped_refptr<QuicAckNotifier::DelegateInterface>* delegate_out, 345 scoped_refptr<QuicAckNotifier::DelegateInterface>* delegate_out,
346 QuicAckNotifier::DelegateInterface* delegate) { 346 QuicAckNotifier::DelegateInterface* delegate) {
347 *delegate_out = delegate; 347 *delegate_out = delegate;
348 } 348 }
349 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithQuicAckNotifier) { 349 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithQuicAckNotifier) {
350 Initialize(kShouldProcessData); 350 Initialize(kShouldProcessData);
351 351
352 scoped_refptr<MockAckNotifierDelegate> delegate( 352 scoped_refptr<MockAckNotifierDelegate> delegate(
353 new StrictMock<MockAckNotifierDelegate>); 353 new StrictMock<MockAckNotifierDelegate>);
354 354
355 const int kDataSize = 16 * 1024; 355 const int kDataSize = 16 * 1024;
356 const string kData(kDataSize, 'a'); 356 const string kData(kDataSize, 'a');
357 357
358 const int kFirstWriteSize = 100; 358 const int kFirstWriteSize = 100;
359 const int kSecondWriteSize = 50; 359 const int kSecondWriteSize = 50;
360 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; 360 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize;
361 361
362 // Set a large flow control send window so this doesn't interfere with test.
363 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
364
362 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; 365 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate;
363 366
364 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( 367 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll(
365 WithArgs<4>(Invoke(CreateFunctor( 368 WithArgs<4>(Invoke(CreateFunctor(
366 &SaveProxyAckNotifierDelegate, &proxy_delegate))), 369 &SaveProxyAckNotifierDelegate, &proxy_delegate))),
367 Return(QuicConsumedData(kFirstWriteSize, false)))); 370 Return(QuicConsumedData(kFirstWriteSize, false))));
368 stream_->WriteOrBufferData(kData, false, delegate.get()); 371 stream_->WriteOrBufferData(kData, false, delegate.get());
369 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); 372 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams());
370 373
371 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). 374 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())).
(...skipping 29 matching lines...) Expand all
401 Initialize(kShouldProcessData); 404 Initialize(kShouldProcessData);
402 405
403 scoped_refptr<MockAckNotifierDelegate> delegate( 406 scoped_refptr<MockAckNotifierDelegate> delegate(
404 new StrictMock<MockAckNotifierDelegate>); 407 new StrictMock<MockAckNotifierDelegate>);
405 408
406 const int kDataSize = 16 * 1024; 409 const int kDataSize = 16 * 1024;
407 const string kData(kDataSize, 'a'); 410 const string kData(kDataSize, 'a');
408 411
409 const int kInitialWriteSize = 100; 412 const int kInitialWriteSize = 100;
410 413
414 // Set a large flow control send window so this doesn't interfere with test.
415 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1);
416
411 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; 417 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate;
412 418
413 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( 419 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll(
414 WithArgs<4>(Invoke(CreateFunctor( 420 WithArgs<4>(Invoke(CreateFunctor(
415 &SaveProxyAckNotifierDelegate, &proxy_delegate))), 421 &SaveProxyAckNotifierDelegate, &proxy_delegate))),
416 Return(QuicConsumedData(kInitialWriteSize, false)))); 422 Return(QuicConsumedData(kInitialWriteSize, false))));
417 stream_->WriteOrBufferData(kData, false, delegate.get()); 423 stream_->WriteOrBufferData(kData, false, delegate.get());
418 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); 424 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams());
419 425
420 // Handle the ack of the first write. 426 // Handle the ack of the first write.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 509
504 // Handle the acks. 510 // Handle the acks.
505 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); 511 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_);
506 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_)); 512 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_));
507 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); 513 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_);
508 } 514 }
509 515
510 } // namespace 516 } // namespace
511 } // namespace test 517 } // namespace test
512 } // namespace net 518 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/reliable_quic_stream.cc ('k') | net/quic/test_tools/quic_flow_controller_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698