| 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/core/quic_flow_controller.h" | 5 #include "net/quic/core/quic_flow_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/quic/platform/api/quic_str_cat.h" | 9 #include "net/quic/platform/api/quic_str_cat.h" |
| 10 #include "net/quic/platform/api/quic_test.h" | 10 #include "net/quic/platform/api/quic_test.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 private: | 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(MockFlowController); | 32 DISALLOW_COPY_AND_ASSIGN(MockFlowController); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class QuicFlowControllerTest : public QuicTest { | 35 class QuicFlowControllerTest : public QuicTest { |
| 36 public: | 36 public: |
| 37 QuicFlowControllerTest() | 37 QuicFlowControllerTest() |
| 38 : stream_id_(1234), | 38 : stream_id_(1234), |
| 39 send_window_(kInitialSessionFlowControlWindowForTest), | 39 send_window_(kInitialSessionFlowControlWindowForTest), |
| 40 receive_window_(kInitialSessionFlowControlWindowForTest), | 40 receive_window_(kInitialSessionFlowControlWindowForTest), |
| 41 connection_(&helper_, &alarm_factory_, Perspective::IS_CLIENT) { | 41 connection_(&helper_, &alarm_factory_, Perspective::IS_CLIENT) {} |
| 42 FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune = true; | |
| 43 } | |
| 44 | 42 |
| 45 void Initialize() { | 43 void Initialize() { |
| 46 flow_controller_.reset(new QuicFlowController( | 44 flow_controller_.reset(new QuicFlowController( |
| 47 &connection_, stream_id_, Perspective::IS_CLIENT, send_window_, | 45 &connection_, stream_id_, Perspective::IS_CLIENT, send_window_, |
| 48 receive_window_, false, &session_flow_controller_)); | 46 receive_window_, false, &session_flow_controller_)); |
| 49 } | 47 } |
| 50 | 48 |
| 51 protected: | 49 protected: |
| 52 QuicStreamId stream_id_; | 50 QuicStreamId stream_id_; |
| 53 QuicByteCount send_window_; | 51 QuicByteCount send_window_; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 flow_controller_->AddBytesSent(send_window_); | 158 flow_controller_->AddBytesSent(send_window_); |
| 161 EXPECT_TRUE(flow_controller_->IsBlocked()); | 159 EXPECT_TRUE(flow_controller_->IsBlocked()); |
| 162 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 160 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
| 163 | 161 |
| 164 // BLOCKED frame should get sent as send offset has changed. | 162 // BLOCKED frame should get sent as send offset has changed. |
| 165 flow_controller_->MaybeSendBlocked(); | 163 flow_controller_->MaybeSendBlocked(); |
| 166 } | 164 } |
| 167 | 165 |
| 168 TEST_F(QuicFlowControllerTest, ReceivingBytesFastIncreasesFlowWindow) { | 166 TEST_F(QuicFlowControllerTest, ReceivingBytesFastIncreasesFlowWindow) { |
| 169 // This test will generate two WINDOW_UPDATE frames. | 167 // This test will generate two WINDOW_UPDATE frames. |
| 170 if (FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune) { | 168 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(1); |
| 171 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)) | |
| 172 .Times(1); | |
| 173 } else { | |
| 174 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)) | |
| 175 .Times(2); | |
| 176 } | |
| 177 | 169 |
| 178 Initialize(); | 170 Initialize(); |
| 179 flow_controller_->set_auto_tune_receive_window(true); | 171 flow_controller_->set_auto_tune_receive_window(true); |
| 180 | 172 |
| 181 // Make sure clock is inititialized. | 173 // Make sure clock is inititialized. |
| 182 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 174 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 183 | 175 |
| 184 QuicSentPacketManager* manager = | 176 QuicSentPacketManager* manager = |
| 185 QuicConnectionPeer::GetSentPacketManager(&connection_); | 177 QuicConnectionPeer::GetSentPacketManager(&connection_); |
| 186 | 178 |
| 187 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); | 179 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); |
| 188 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), | 180 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), |
| 189 QuicTime::Delta::Zero(), QuicTime::Zero()); | 181 QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 190 | 182 |
| 191 EXPECT_FALSE(flow_controller_->IsBlocked()); | 183 EXPECT_FALSE(flow_controller_->IsBlocked()); |
| 192 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 184 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 193 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | 185 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, |
| 194 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 186 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 195 | 187 |
| 196 QuicByteCount threshold = | 188 QuicByteCount threshold = |
| 197 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 189 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 198 | 190 |
| 199 QuicStreamOffset receive_offset = threshold + 1; | 191 QuicStreamOffset receive_offset = threshold + 1; |
| 200 // Receive some bytes, updating highest received offset, but not enough to | 192 // Receive some bytes, updating highest received offset, but not enough to |
| 201 // fill flow control receive window. | 193 // fill flow control receive window. |
| 202 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 194 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 203 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 195 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 204 EXPECT_EQ(kInitialSessionFlowControlWindowForTest - receive_offset, | 196 EXPECT_EQ(kInitialSessionFlowControlWindowForTest - receive_offset, |
| 205 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 197 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 206 if (FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune) { | 198 EXPECT_CALL( |
| 207 EXPECT_CALL( | 199 session_flow_controller_, |
| 208 session_flow_controller_, | 200 EnsureWindowAtLeast(kInitialSessionFlowControlWindowForTest * 2 * 1.5)); |
| 209 EnsureWindowAtLeast(kInitialSessionFlowControlWindowForTest * 2 * 1.5)); | |
| 210 } | |
| 211 | 201 |
| 212 // Consume enough bytes to send a WINDOW_UPDATE frame. | 202 // Consume enough bytes to send a WINDOW_UPDATE frame. |
| 213 flow_controller_->AddBytesConsumed(threshold + 1); | 203 flow_controller_->AddBytesConsumed(threshold + 1); |
| 214 // Result is that once again we have a fully open receive window. | 204 // Result is that once again we have a fully open receive window. |
| 215 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 205 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 216 if (FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune) { | 206 EXPECT_EQ(2 * kInitialSessionFlowControlWindowForTest, |
| 217 EXPECT_EQ( | 207 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 218 2 * kInitialSessionFlowControlWindowForTest, | |
| 219 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 220 } else { | |
| 221 EXPECT_EQ( | |
| 222 kInitialSessionFlowControlWindowForTest, | |
| 223 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 224 | |
| 225 // Move time forward, but by less than two RTTs. Then receive and consume | |
| 226 // some more, forcing a second WINDOW_UPDATE with an increased max window | |
| 227 // size. | |
| 228 EXPECT_CALL( | |
| 229 session_flow_controller_, | |
| 230 EnsureWindowAtLeast(kInitialSessionFlowControlWindowForTest * 2 * 1.5)); | |
| 231 } | |
| 232 | 208 |
| 233 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt - 1)); | 209 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt - 1)); |
| 234 receive_offset += threshold + 1; | 210 receive_offset += threshold + 1; |
| 235 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 211 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 236 flow_controller_->AddBytesConsumed(threshold + 1); | 212 flow_controller_->AddBytesConsumed(threshold + 1); |
| 237 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 213 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 238 QuicByteCount new_threshold = | 214 QuicByteCount new_threshold = |
| 239 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 215 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 240 EXPECT_GT(new_threshold, threshold); | 216 EXPECT_GT(new_threshold, threshold); |
| 241 } | 217 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 264 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 289 flow_controller_->AddBytesConsumed(threshold + 1); | 265 flow_controller_->AddBytesConsumed(threshold + 1); |
| 290 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 266 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 291 QuicByteCount new_threshold = | 267 QuicByteCount new_threshold = |
| 292 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 268 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 293 EXPECT_EQ(new_threshold, threshold); | 269 EXPECT_EQ(new_threshold, threshold); |
| 294 } | 270 } |
| 295 | 271 |
| 296 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStableFlowWindow) { | 272 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStableFlowWindow) { |
| 297 // This test will generate two WINDOW_UPDATE frames. | 273 // This test will generate two WINDOW_UPDATE frames. |
| 298 if (FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune) { | 274 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(1); |
| 299 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)) | |
| 300 .Times(1); | |
| 301 } else { | |
| 302 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)) | |
| 303 .Times(2); | |
| 304 } | |
| 305 | 275 |
| 306 Initialize(); | 276 Initialize(); |
| 307 flow_controller_->set_auto_tune_receive_window(true); | 277 flow_controller_->set_auto_tune_receive_window(true); |
| 308 | 278 |
| 309 // Make sure clock is inititialized. | 279 // Make sure clock is inititialized. |
| 310 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 280 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 311 | 281 |
| 312 QuicSentPacketManager* manager = | 282 QuicSentPacketManager* manager = |
| 313 QuicConnectionPeer::GetSentPacketManager(&connection_); | 283 QuicConnectionPeer::GetSentPacketManager(&connection_); |
| 314 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); | 284 RttStats* rtt_stats = const_cast<RttStats*>(manager->GetRttStats()); |
| 315 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), | 285 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), |
| 316 QuicTime::Delta::Zero(), QuicTime::Zero()); | 286 QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 317 | 287 |
| 318 EXPECT_FALSE(flow_controller_->IsBlocked()); | 288 EXPECT_FALSE(flow_controller_->IsBlocked()); |
| 319 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 289 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 320 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | 290 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, |
| 321 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 291 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 322 | 292 |
| 323 QuicByteCount threshold = | 293 QuicByteCount threshold = |
| 324 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 294 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 325 | 295 |
| 326 QuicStreamOffset receive_offset = threshold + 1; | 296 QuicStreamOffset receive_offset = threshold + 1; |
| 327 // Receive some bytes, updating highest received offset, but not enough to | 297 // Receive some bytes, updating highest received offset, but not enough to |
| 328 // fill flow control receive window. | 298 // fill flow control receive window. |
| 329 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 299 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 330 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 300 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 331 EXPECT_EQ(kInitialSessionFlowControlWindowForTest - receive_offset, | 301 EXPECT_EQ(kInitialSessionFlowControlWindowForTest - receive_offset, |
| 332 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 302 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 333 if (FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune) { | 303 EXPECT_CALL( |
| 334 EXPECT_CALL( | 304 session_flow_controller_, |
| 335 session_flow_controller_, | 305 EnsureWindowAtLeast(kInitialSessionFlowControlWindowForTest * 2 * 1.5)); |
| 336 EnsureWindowAtLeast(kInitialSessionFlowControlWindowForTest * 2 * 1.5)); | |
| 337 } | |
| 338 flow_controller_->AddBytesConsumed(threshold + 1); | 306 flow_controller_->AddBytesConsumed(threshold + 1); |
| 339 | 307 |
| 340 // Result is that once again we have a fully open receive window. | 308 // Result is that once again we have a fully open receive window. |
| 341 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 309 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 342 if (FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune) { | 310 EXPECT_EQ(2 * kInitialSessionFlowControlWindowForTest, |
| 343 EXPECT_EQ( | 311 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 344 2 * kInitialSessionFlowControlWindowForTest, | |
| 345 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 346 } else { | |
| 347 EXPECT_EQ( | |
| 348 kInitialSessionFlowControlWindowForTest, | |
| 349 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 350 } | |
| 351 | 312 |
| 352 // Move time forward, but by more than two RTTs. Then receive and consume | 313 // Move time forward, but by more than two RTTs. Then receive and consume |
| 353 // some more, forcing a second WINDOW_UPDATE with unchanged max window size. | 314 // some more, forcing a second WINDOW_UPDATE with unchanged max window size. |
| 354 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt + 1)); | 315 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt + 1)); |
| 355 | 316 |
| 356 receive_offset += threshold + 1; | 317 receive_offset += threshold + 1; |
| 357 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 318 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 358 | 319 |
| 359 flow_controller_->AddBytesConsumed(threshold + 1); | 320 flow_controller_->AddBytesConsumed(threshold + 1); |
| 360 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 321 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 361 | 322 |
| 362 QuicByteCount new_threshold = | 323 QuicByteCount new_threshold = |
| 363 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 324 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 364 if (FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune) { | 325 EXPECT_EQ(new_threshold, 2 * threshold); |
| 365 EXPECT_EQ(new_threshold, 2 * threshold); | |
| 366 } else { | |
| 367 EXPECT_EQ(new_threshold, threshold); | |
| 368 } | |
| 369 } | 326 } |
| 370 | 327 |
| 371 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalNoAutoTune) { | 328 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalNoAutoTune) { |
| 372 // This test will generate two WINDOW_UPDATE frames. | 329 // This test will generate two WINDOW_UPDATE frames. |
| 373 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | 330 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); |
| 374 | 331 |
| 375 Initialize(); | 332 Initialize(); |
| 376 flow_controller_->set_auto_tune_receive_window(false); | 333 flow_controller_->set_auto_tune_receive_window(false); |
| 377 | 334 |
| 378 // Make sure clock is inititialized. | 335 // Make sure clock is inititialized. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 375 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 419 | 376 |
| 420 QuicByteCount new_threshold = | 377 QuicByteCount new_threshold = |
| 421 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 378 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 422 | 379 |
| 423 EXPECT_EQ(new_threshold, threshold); | 380 EXPECT_EQ(new_threshold, threshold); |
| 424 } | 381 } |
| 425 | 382 |
| 426 } // namespace test | 383 } // namespace test |
| 427 } // namespace net | 384 } // namespace net |
| OLD | NEW |