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/congestion_control/rtt_stats.h" | 5 #include "net/quic/congestion_control/rtt_stats.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/test/scoped_mock_log.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
9 | 12 |
| 13 using logging::LOG_WARNING; |
| 14 using std::vector; |
| 15 using testing::HasSubstr; |
| 16 using testing::Message; |
| 17 using testing::_; |
| 18 |
10 namespace net { | 19 namespace net { |
11 namespace test { | 20 namespace test { |
12 | 21 |
13 class RttStatsPeer { | 22 class RttStatsPeer { |
14 public: | 23 public: |
15 static QuicTime::Delta GetHalfWindowRtt(const RttStats* rtt_stats) { | 24 static QuicTime::Delta GetHalfWindowRtt(const RttStats* rtt_stats) { |
16 return rtt_stats->half_window_rtt_.rtt; | 25 return rtt_stats->half_window_rtt_.rtt; |
17 } | 26 } |
18 | 27 |
19 static QuicTime::Delta GetQuarterWindowRtt(const RttStats* rtt_stats) { | 28 static QuicTime::Delta GetQuarterWindowRtt(const RttStats* rtt_stats) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 EXPECT_EQ(initial_rtt.Multiply(0.875), rtt_stats_.mean_deviation()); | 219 EXPECT_EQ(initial_rtt.Multiply(0.875), rtt_stats_.mean_deviation()); |
211 | 220 |
212 // Now go back down to 5ms and expire the smoothed metrics, and ensure the | 221 // Now go back down to 5ms and expire the smoothed metrics, and ensure the |
213 // mean deviation increases to 15ms. | 222 // mean deviation increases to 15ms. |
214 QuicTime::Delta half_rtt = initial_rtt.Multiply(0.5); | 223 QuicTime::Delta half_rtt = initial_rtt.Multiply(0.5); |
215 rtt_stats_.UpdateRtt(half_rtt, QuicTime::Delta::Zero(), QuicTime::Zero()); | 224 rtt_stats_.UpdateRtt(half_rtt, QuicTime::Delta::Zero(), QuicTime::Zero()); |
216 EXPECT_GT(doubled_rtt, rtt_stats_.SmoothedRtt()); | 225 EXPECT_GT(doubled_rtt, rtt_stats_.SmoothedRtt()); |
217 EXPECT_LT(initial_rtt, rtt_stats_.mean_deviation()); | 226 EXPECT_LT(initial_rtt, rtt_stats_.mean_deviation()); |
218 } | 227 } |
219 | 228 |
| 229 TEST_F(RttStatsTest, UpdateRttWithBadSendDeltas) { |
| 230 // Make sure we ignore bad RTTs. |
| 231 ScopedMockLog log; |
| 232 |
| 233 QuicTime::Delta initial_rtt = QuicTime::Delta::FromMilliseconds(10); |
| 234 rtt_stats_.UpdateRtt(initial_rtt, QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 235 EXPECT_EQ(initial_rtt, rtt_stats_.MinRtt()); |
| 236 EXPECT_EQ(initial_rtt, rtt_stats_.recent_min_rtt()); |
| 237 EXPECT_EQ(initial_rtt, rtt_stats_.SmoothedRtt()); |
| 238 |
| 239 vector<QuicTime::Delta> bad_send_deltas; |
| 240 bad_send_deltas.push_back(QuicTime::Delta::Zero()); |
| 241 bad_send_deltas.push_back(QuicTime::Delta::Infinite()); |
| 242 bad_send_deltas.push_back(QuicTime::Delta::FromMicroseconds(-1000)); |
| 243 log.StartCapturingLogs(); |
| 244 |
| 245 for (QuicTime::Delta bad_send_delta : bad_send_deltas) { |
| 246 SCOPED_TRACE(Message() << "bad_send_delta = " |
| 247 << bad_send_delta.ToMicroseconds()); |
| 248 EXPECT_CALL(log, Log(LOG_WARNING, _, _, _, HasSubstr("Ignoring"))); |
| 249 rtt_stats_.UpdateRtt(bad_send_delta, |
| 250 QuicTime::Delta::Zero(), |
| 251 QuicTime::Zero()); |
| 252 EXPECT_EQ(initial_rtt, rtt_stats_.MinRtt()); |
| 253 EXPECT_EQ(initial_rtt, rtt_stats_.recent_min_rtt()); |
| 254 EXPECT_EQ(initial_rtt, rtt_stats_.SmoothedRtt()); |
| 255 } |
| 256 } |
| 257 |
220 } // namespace test | 258 } // namespace test |
221 } // namespace net | 259 } // namespace net |
OLD | NEW |