| 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 "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.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" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 146 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
| 147 flow_controller_->AddBytesSent(send_window_); | 147 flow_controller_->AddBytesSent(send_window_); |
| 148 EXPECT_TRUE(flow_controller_->IsBlocked()); | 148 EXPECT_TRUE(flow_controller_->IsBlocked()); |
| 149 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 149 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
| 150 | 150 |
| 151 // BLOCKED frame should get sent as send offset has changed. | 151 // BLOCKED frame should get sent as send offset has changed. |
| 152 flow_controller_->MaybeSendBlocked(); | 152 flow_controller_->MaybeSendBlocked(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST_F(QuicFlowControllerTest, ReceivingBytesFastIncreasesFlowWindow) { | 155 TEST_F(QuicFlowControllerTest, ReceivingBytesFastIncreasesFlowWindow) { |
| 156 ValueRestore<bool> old_flag(&FLAGS_quic_auto_tune_receive_window, true); | |
| 157 // This test will generate two WINDOW_UPDATE frames. | 156 // This test will generate two WINDOW_UPDATE frames. |
| 158 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | 157 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); |
| 159 | 158 |
| 160 Initialize(); | 159 Initialize(); |
| 161 flow_controller_->set_auto_tune_receive_window(true); | 160 flow_controller_->set_auto_tune_receive_window(true); |
| 162 | 161 |
| 163 // Make sure clock is inititialized. | 162 // Make sure clock is inititialized. |
| 164 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 163 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 165 | 164 |
| 166 QuicSentPacketManager* manager = | 165 QuicSentPacketManager* manager = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt - 1)); | 198 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt - 1)); |
| 200 receive_offset += threshold + 1; | 199 receive_offset += threshold + 1; |
| 201 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | 200 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); |
| 202 flow_controller_->AddBytesConsumed(threshold + 1); | 201 flow_controller_->AddBytesConsumed(threshold + 1); |
| 203 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 202 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 204 QuicByteCount new_threshold = | 203 QuicByteCount new_threshold = |
| 205 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 204 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 206 EXPECT_GT(new_threshold, threshold); | 205 EXPECT_GT(new_threshold, threshold); |
| 207 } | 206 } |
| 208 | 207 |
| 209 TEST_F(QuicFlowControllerTest, ReceivingBytesFastStatusQuo) { | 208 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStableFlowWindow) { |
| 210 ValueRestore<bool> old_flag(&FLAGS_quic_auto_tune_receive_window, false); | |
| 211 // This test will generate two WINDOW_UPDATE frames. | 209 // This test will generate two WINDOW_UPDATE frames. |
| 212 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | 210 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); |
| 213 | 211 |
| 214 Initialize(); | |
| 215 flow_controller_->set_auto_tune_receive_window(true); | |
| 216 | |
| 217 // Make sure clock is inititialized. | |
| 218 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | |
| 219 | |
| 220 QuicSentPacketManager* manager = | |
| 221 QuicConnectionPeer::GetSentPacketManager(&connection_); | |
| 222 | |
| 223 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager); | |
| 224 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), | |
| 225 QuicTime::Delta::Zero(), QuicTime::Zero()); | |
| 226 | |
| 227 EXPECT_FALSE(flow_controller_->IsBlocked()); | |
| 228 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 229 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | |
| 230 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 231 | |
| 232 QuicByteCount threshold = | |
| 233 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | |
| 234 | |
| 235 QuicStreamOffset receive_offset = threshold + 1; | |
| 236 // Receive some bytes, updating highest received offset, but not enough to | |
| 237 // fill flow control receive window. | |
| 238 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | |
| 239 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 240 EXPECT_EQ(kInitialSessionFlowControlWindowForTest - receive_offset, | |
| 241 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 242 | |
| 243 // Consume enough bytes to send a WINDOW_UPDATE frame. | |
| 244 flow_controller_->AddBytesConsumed(threshold + 1); | |
| 245 // Result is that once again we have a fully open receive window. | |
| 246 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 247 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | |
| 248 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 249 | |
| 250 // Move time forward, but by less than two RTTs. Then receive and consume | |
| 251 // some more, forcing a second WINDOW_UPDATE with an increased max window | |
| 252 // size. | |
| 253 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt - 1)); | |
| 254 receive_offset += threshold + 1; | |
| 255 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | |
| 256 flow_controller_->AddBytesConsumed(threshold + 1); | |
| 257 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 258 QuicByteCount new_threshold = | |
| 259 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | |
| 260 EXPECT_EQ(new_threshold, threshold); | |
| 261 } | |
| 262 | |
| 263 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStableFlowWindow) { | |
| 264 ValueRestore<bool> old_flag(&FLAGS_quic_auto_tune_receive_window, true); | |
| 265 // This test will generate two WINDOW_UPDATE frames. | |
| 266 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | |
| 267 | |
| 268 Initialize(); | |
| 269 flow_controller_->set_auto_tune_receive_window(true); | |
| 270 | |
| 271 // Make sure clock is inititialized. | |
| 272 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | |
| 273 | |
| 274 QuicSentPacketManager* manager = | |
| 275 QuicConnectionPeer::GetSentPacketManager(&connection_); | |
| 276 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager); | |
| 277 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), | |
| 278 QuicTime::Delta::Zero(), QuicTime::Zero()); | |
| 279 | |
| 280 EXPECT_FALSE(flow_controller_->IsBlocked()); | |
| 281 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 282 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | |
| 283 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 284 | |
| 285 QuicByteCount threshold = | |
| 286 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | |
| 287 | |
| 288 QuicStreamOffset receive_offset = threshold + 1; | |
| 289 // Receive some bytes, updating highest received offset, but not enough to | |
| 290 // fill flow control receive window. | |
| 291 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | |
| 292 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 293 EXPECT_EQ(kInitialSessionFlowControlWindowForTest - receive_offset, | |
| 294 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 295 | |
| 296 flow_controller_->AddBytesConsumed(threshold + 1); | |
| 297 | |
| 298 // Result is that once again we have a fully open receive window. | |
| 299 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 300 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | |
| 301 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | |
| 302 | |
| 303 // Move time forward, but by more than two RTTs. Then receive and consume | |
| 304 // some more, forcing a second WINDOW_UPDATE with unchanged max window size. | |
| 305 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2 * kRtt + 1)); | |
| 306 | |
| 307 receive_offset += threshold + 1; | |
| 308 EXPECT_TRUE(flow_controller_->UpdateHighestReceivedOffset(receive_offset)); | |
| 309 | |
| 310 flow_controller_->AddBytesConsumed(threshold + 1); | |
| 311 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | |
| 312 | |
| 313 QuicByteCount new_threshold = | |
| 314 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | |
| 315 | |
| 316 EXPECT_EQ(new_threshold, threshold); | |
| 317 } | |
| 318 | |
| 319 TEST_F(QuicFlowControllerTest, ReceivingBytesNormalStatusQuo) { | |
| 320 ValueRestore<bool> old_flag(&FLAGS_quic_auto_tune_receive_window, false); | |
| 321 // This test will generate two WINDOW_UPDATE frames. | |
| 322 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(2); | |
| 323 | |
| 324 Initialize(); | 212 Initialize(); |
| 325 flow_controller_->set_auto_tune_receive_window(true); | 213 flow_controller_->set_auto_tune_receive_window(true); |
| 326 | 214 |
| 327 // Make sure clock is inititialized. | 215 // Make sure clock is inititialized. |
| 328 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 216 connection_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 329 | 217 |
| 330 QuicSentPacketManager* manager = | 218 QuicSentPacketManager* manager = |
| 331 QuicConnectionPeer::GetSentPacketManager(&connection_); | 219 QuicConnectionPeer::GetSentPacketManager(&connection_); |
| 332 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager); | 220 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager); |
| 333 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), | 221 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRtt), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 255 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 368 | 256 |
| 369 QuicByteCount new_threshold = | 257 QuicByteCount new_threshold = |
| 370 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 258 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 371 | 259 |
| 372 EXPECT_EQ(new_threshold, threshold); | 260 EXPECT_EQ(new_threshold, threshold); |
| 373 } | 261 } |
| 374 | 262 |
| 375 } // namespace test | 263 } // namespace test |
| 376 } // namespace net | 264 } // namespace net |
| OLD | NEW |