| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic_flow_controller.h" | 5 #include "net/quic/quic_flow_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 149 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
| 150 flow_controller_->AddBytesSent(send_window_); | 150 flow_controller_->AddBytesSent(send_window_); |
| 151 EXPECT_TRUE(flow_controller_->IsBlocked()); | 151 EXPECT_TRUE(flow_controller_->IsBlocked()); |
| 152 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 152 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
| 153 | 153 |
| 154 // BLOCKED frame should get sent as send offset has changed. | 154 // BLOCKED frame should get sent as send offset has changed. |
| 155 flow_controller_->MaybeSendBlocked(); | 155 flow_controller_->MaybeSendBlocked(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 TEST_F(QuicFlowControllerTest, ReceivingBytesFastIncreasesFlowWindow) { | 158 TEST_F(QuicFlowControllerTest, ReceivingBytesFastIncreasesFlowWindow) { |
| 159 FLAGS_quic_auto_tune_receive_window = true; | |
| 160 // This test will generate two WINDOW_UPDATE frames. | 159 // This test will generate two WINDOW_UPDATE frames. |
| 161 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | 160 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); |
| 162 | 161 |
| 163 Initialize(); | 162 Initialize(); |
| 164 flow_controller_->set_auto_tune_receive_window(true); | 163 flow_controller_->set_auto_tune_receive_window(true); |
| 165 | 164 |
| 166 // Make sure clock is inititialized. | 165 // Make sure clock is inititialized. |
| 167 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 166 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 168 | 167 |
| 169 QuicSentPacketManagerInterface* manager = | 168 QuicSentPacketManagerInterface* manager = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt - 1)); | 201 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt - 1)); |
| 203 receive_offset += threshold + 1; | 202 receive_offset += threshold + 1; |
| 204 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 203 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 205 flow_controller_->AddBytesConsumed(threshold + 1); | 204 flow_controller_->AddBytesConsumed(threshold + 1); |
| 206 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 205 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 207 QuicByteCount new_threshold = | 206 QuicByteCount new_threshold = |
| 208 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 207 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 209 EXPECT_GT(new_threshold, threshold); | 208 EXPECT_GT(new_threshold, threshold); |
| 210 } | 209 } |
| 211 | 210 |
| 212 TEST_F(QuicFlowControllerTest, ReceivingBytesFastStatusQuo) { | 211 TEST_F(QuicFlowControllerTest, ReceivingBytesFastNoAutoTune) { |
| 213 FLAGS_quic_auto_tune_receive_window = false; | |
| 214 // This test will generate two WINDOW_UPDATE frames. | 212 // This test will generate two WINDOW_UPDATE frames. |
| 215 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | 213 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); |
| 216 | 214 |
| 217 Initialize(); | 215 Initialize(); |
| 218 flow_controller_->set_auto_tune_receive_window(true); | 216 flow_controller_->set_auto_tune_receive_window(false); |
| 219 | 217 |
| 220 // Make sure clock is inititialized. | 218 // Make sure clock is inititialized. |
| 221 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 219 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 222 | 220 |
| 223 QuicSentPacketManagerInterface* manager = | 221 QuicSentPacketManagerInterface* manager = |
| 224 QuicConnectionPeer::GetSentPacketManager(&connection_, kDefaultPathId); | 222 QuicConnectionPeer::GetSentPacketManager(&connection_, kDefaultPathId); |
| 225 | 223 |
| 226 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); | 224 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); |
| 227 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), | 225 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), |
| 228 QuicTime::Delta::Zero(), QuicTime::Zero()); | 226 QuicTime::Delta::Zero(), QuicTime::Zero()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 257 receive_offset += threshold + 1; | 255 receive_offset += threshold + 1; |
| 258 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 256 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 259 flow_controller_->AddBytesConsumed(threshold + 1); | 257 flow_controller_->AddBytesConsumed(threshold + 1); |
| 260 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 258 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 261 QuicByteCount new_threshold = | 259 QuicByteCount new_threshold = |
| 262 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 260 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 263 EXPECT_EQ(new_threshold, threshold); | 261 EXPECT_EQ(new_threshold, threshold); |
| 264 } | 262 } |
| 265 | 263 |
| 266 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStableFlowWindow) { | 264 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStableFlowWindow) { |
| 267 FLAGS_quic_auto_tune_receive_window = true; | |
| 268 // This test will generate two WINDOW_UPDATE frames. | 265 // This test will generate two WINDOW_UPDATE frames. |
| 269 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | 266 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); |
| 270 | 267 |
| 271 Initialize(); | 268 Initialize(); |
| 272 flow_controller_->set_auto_tune_receive_window(true); | 269 flow_controller_->set_auto_tune_receive_window(true); |
| 273 | 270 |
| 274 // Make sure clock is inititialized. | 271 // Make sure clock is inititialized. |
| 275 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 272 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 276 | 273 |
| 277 QuicSentPacketManagerInterface* manager = | 274 QuicSentPacketManagerInterface* manager = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 309 |
| 313 flow_controller_->AddBytesConsumed(threshold + 1); | 310 flow_controller_->AddBytesConsumed(threshold + 1); |
| 314 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 311 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 315 | 312 |
| 316 QuicByteCount new_threshold = | 313 QuicByteCount new_threshold = |
| 317 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 314 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 318 | 315 |
| 319 EXPECT_EQ(new_threshold, threshold); | 316 EXPECT_EQ(new_threshold, threshold); |
| 320 } | 317 } |
| 321 | 318 |
| 322 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStatusQuo) { | 319 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalNoAutoTune) { |
| 323 FLAGS_quic_auto_tune_receive_window = false; | |
| 324 // This test will generate two WINDOW_UPDATE frames. | 320 // This test will generate two WINDOW_UPDATE frames. |
| 325 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | 321 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); |
| 326 | 322 |
| 327 Initialize(); | 323 Initialize(); |
| 328 flow_controller_->set_auto_tune_receive_window(true); | 324 flow_controller_->set_auto_tune_receive_window(false); |
| 329 | 325 |
| 330 // Make sure clock is inititialized. | 326 // Make sure clock is inititialized. |
| 331 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 327 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 332 | 328 |
| 333 QuicSentPacketManagerInterface* manager = | 329 QuicSentPacketManagerInterface* manager = |
| 334 QuicConnectionPeer::GetSentPacketManager(&connection_, kDefaultPathId); | 330 QuicConnectionPeer::GetSentPacketManager(&connection_, kDefaultPathId); |
| 335 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); | 331 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); |
| 336 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), | 332 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), |
| 337 QuicTime::Delta::Zero(), QuicTime::Zero()); | 333 QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 338 | 334 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 366 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 371 | 367 |
| 372 QuicByteCount new_threshold = | 368 QuicByteCount new_threshold = |
| 373 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 369 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 374 | 370 |
| 375 EXPECT_EQ(new_threshold, threshold); | 371 EXPECT_EQ(new_threshold, threshold); |
| 376 } | 372 } |
| 377 | 373 |
| 378 } // namespace test | 374 } // namespace test |
| 379 } // namespace net | 375 } // namespace net |
| OLD | NEW |