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/congestion_control/rtt_stats.h" | 5 #include "net/quic/core/congestion_control/rtt_stats.h" |
6 | 6 |
| 7 #include <cmath> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/test/mock_log.h" | 11 #include "base/test/mock_log.h" |
11 #include "net/quic/core/quic_flags.h" | 12 #include "net/quic/core/quic_flags.h" |
12 #include "net/quic/test_tools/rtt_stats_peer.h" | 13 #include "net/quic/test_tools/rtt_stats_peer.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using logging::LOG_WARNING; | 16 using logging::LOG_WARNING; |
16 using std::vector; | 17 using std::vector; |
(...skipping 29 matching lines...) Expand all Loading... |
46 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.latest_rtt()); | 47 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.latest_rtt()); |
47 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.smoothed_rtt()); | 48 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.smoothed_rtt()); |
48 // Verify that large erroneous ack_delay does not change Smoothed RTT. | 49 // Verify that large erroneous ack_delay does not change Smoothed RTT. |
49 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(200), | 50 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(200), |
50 QuicTime::Delta::FromMilliseconds(300), | 51 QuicTime::Delta::FromMilliseconds(300), |
51 QuicTime::Zero()); | 52 QuicTime::Zero()); |
52 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.latest_rtt()); | 53 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.latest_rtt()); |
53 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.smoothed_rtt()); | 54 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.smoothed_rtt()); |
54 } | 55 } |
55 | 56 |
| 57 // Ensure that the potential rounding artifacts in EWMA calculation do not cause |
| 58 // the SRTT to drift too far from the exact value. |
| 59 TEST_F(RttStatsTest, SmoothedRttStability) { |
| 60 for (size_t time = 3; time < 20000; time++) { |
| 61 RttStats stats; |
| 62 for (size_t i = 0; i < 100; i++) { |
| 63 stats.UpdateRtt(QuicTime::Delta::FromMicroseconds(time), |
| 64 QuicTime::Delta::FromMilliseconds(0), QuicTime::Zero()); |
| 65 int64_t time_delta_us = stats.smoothed_rtt().ToMicroseconds() - time; |
| 66 ASSERT_LE(std::abs(time_delta_us), 1); |
| 67 } |
| 68 } |
| 69 } |
| 70 |
56 TEST_F(RttStatsTest, PreviousSmoothedRtt) { | 71 TEST_F(RttStatsTest, PreviousSmoothedRtt) { |
57 // Verify that ack_delay is corrected for in Smoothed RTT. | 72 // Verify that ack_delay is corrected for in Smoothed RTT. |
58 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(300), | 73 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(300), |
59 QuicTime::Delta::FromMilliseconds(100), | 74 QuicTime::Delta::FromMilliseconds(100), |
60 QuicTime::Zero()); | 75 QuicTime::Zero()); |
61 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.latest_rtt()); | 76 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.latest_rtt()); |
62 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.smoothed_rtt()); | 77 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), rtt_stats_.smoothed_rtt()); |
63 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.previous_srtt()); | 78 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.previous_srtt()); |
64 // Ensure the previous SRTT is 200ms after a 100ms sample. | 79 // Ensure the previous SRTT is 200ms after a 100ms sample. |
65 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100), | 80 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // Reset rtt stats on connection migrations. | 208 // Reset rtt stats on connection migrations. |
194 rtt_stats_.OnConnectionMigration(); | 209 rtt_stats_.OnConnectionMigration(); |
195 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.latest_rtt()); | 210 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.latest_rtt()); |
196 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.smoothed_rtt()); | 211 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.smoothed_rtt()); |
197 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.min_rtt()); | 212 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.min_rtt()); |
198 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.WindowedMinRtt()); | 213 EXPECT_EQ(QuicTime::Delta::Zero(), rtt_stats_.WindowedMinRtt()); |
199 } | 214 } |
200 | 215 |
201 } // namespace test | 216 } // namespace test |
202 } // namespace net | 217 } // namespace net |
OLD | NEW |