OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/quic/quic_sustained_bandwidth_recorder.h" |
| 6 |
| 7 #include "net/quic/quic_bandwidth.h" |
| 8 #include "net/quic/quic_time.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace net { |
| 12 namespace test { |
| 13 namespace { |
| 14 |
| 15 TEST(QuicSustainedBandwidthRecorderTest, BandwidthEstimates) { |
| 16 QuicSustainedBandwidthRecorder recorder; |
| 17 EXPECT_FALSE(recorder.HasEstimate()); |
| 18 |
| 19 QuicTime estimate_time = QuicTime::Zero(); |
| 20 QuicWallTime wall_time = QuicWallTime::Zero(); |
| 21 QuicTime::Delta srtt = QuicTime::Delta::FromMilliseconds(150); |
| 22 const int kBandwidthBitsPerSecond = 12345678; |
| 23 QuicBandwidth bandwidth = |
| 24 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond); |
| 25 |
| 26 // This triggers recording, but should not yield a valid estimate yet. |
| 27 recorder.RecordEstimate(true, false, bandwidth, estimate_time, wall_time, |
| 28 srtt); |
| 29 EXPECT_FALSE(recorder.HasEstimate()); |
| 30 |
| 31 // Send a second reading, again this should not result in a valid estimate, |
| 32 // as not enough time has passed. |
| 33 estimate_time = estimate_time.Add(srtt); |
| 34 recorder.RecordEstimate(true, false, bandwidth, estimate_time, wall_time, |
| 35 srtt); |
| 36 EXPECT_FALSE(recorder.HasEstimate()); |
| 37 |
| 38 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. |
| 39 estimate_time = estimate_time.Add(srtt); |
| 40 estimate_time = estimate_time.Add(srtt); |
| 41 recorder.RecordEstimate(true, false, bandwidth, estimate_time, wall_time, |
| 42 srtt); |
| 43 EXPECT_TRUE(recorder.HasEstimate()); |
| 44 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); |
| 45 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); |
| 46 |
| 47 // Resetting, and sending a different estimate will only change output after |
| 48 // a further 3 * kSRTT has passed. |
| 49 QuicBandwidth second_bandwidth = |
| 50 QuicBandwidth::FromBitsPerSecond(2 * kBandwidthBitsPerSecond); |
| 51 // Reset the recorder by passing in an unreliable measurement. |
| 52 recorder.RecordEstimate(false, false, second_bandwidth, estimate_time, |
| 53 wall_time, srtt); |
| 54 recorder.RecordEstimate(true, false, second_bandwidth, estimate_time, |
| 55 wall_time, srtt); |
| 56 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); |
| 57 |
| 58 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
| 59 const int32 kSeconds = 556677; |
| 60 QuicWallTime second_bandwidth_wall_time = |
| 61 QuicWallTime::FromUNIXSeconds(kSeconds); |
| 62 recorder.RecordEstimate(true, false, second_bandwidth, estimate_time, |
| 63 second_bandwidth_wall_time, srtt); |
| 64 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth); |
| 65 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); |
| 66 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); |
| 67 |
| 68 // Reset again, this time recording a lower bandwidth than before. |
| 69 QuicBandwidth third_bandwidth = |
| 70 QuicBandwidth::FromBitsPerSecond(0.5 * kBandwidthBitsPerSecond); |
| 71 // Reset the recorder by passing in an unreliable measurement. |
| 72 recorder.RecordEstimate(false, false, third_bandwidth, estimate_time, |
| 73 wall_time, srtt); |
| 74 recorder.RecordEstimate(true, false, third_bandwidth, estimate_time, |
| 75 wall_time, srtt); |
| 76 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth); |
| 77 |
| 78 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
| 79 recorder.RecordEstimate(true, false, third_bandwidth, estimate_time, |
| 80 wall_time, srtt); |
| 81 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth); |
| 82 |
| 83 // Max bandwidth should not have changed. |
| 84 EXPECT_LT(third_bandwidth, second_bandwidth); |
| 85 EXPECT_EQ(recorder.MaxBandwidthEstimate(), second_bandwidth); |
| 86 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); |
| 87 } |
| 88 |
| 89 TEST(QuicSustainedBandwidthRecorderTest, SlowStart) { |
| 90 // Verify that slow start status is correctly recorded. |
| 91 QuicSustainedBandwidthRecorder recorder; |
| 92 EXPECT_FALSE(recorder.HasEstimate()); |
| 93 |
| 94 QuicTime estimate_time = QuicTime::Zero(); |
| 95 QuicWallTime wall_time = QuicWallTime::Zero(); |
| 96 QuicTime::Delta srtt = QuicTime::Delta::FromMilliseconds(150); |
| 97 const int kBandwidthBitsPerSecond = 12345678; |
| 98 QuicBandwidth bandwidth = |
| 99 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond); |
| 100 |
| 101 bool in_slow_start = true; |
| 102 |
| 103 // This triggers recording, but should not yield a valid estimate yet. |
| 104 recorder.RecordEstimate(true, in_slow_start, bandwidth, estimate_time, |
| 105 wall_time, srtt); |
| 106 |
| 107 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. |
| 108 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
| 109 recorder.RecordEstimate(true, in_slow_start, bandwidth, estimate_time, |
| 110 wall_time, srtt); |
| 111 EXPECT_TRUE(recorder.HasEstimate()); |
| 112 EXPECT_TRUE(recorder.EstimateRecordedDuringSlowStart()); |
| 113 |
| 114 // Now send another estimate, this time not in slow start. |
| 115 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
| 116 in_slow_start = false; |
| 117 recorder.RecordEstimate(true, in_slow_start, bandwidth, estimate_time, |
| 118 wall_time, srtt); |
| 119 EXPECT_TRUE(recorder.HasEstimate()); |
| 120 EXPECT_FALSE(recorder.EstimateRecordedDuringSlowStart()); |
| 121 } |
| 122 |
| 123 } // namespace |
| 124 } // namespace test |
| 125 } // namespace net |
OLD | NEW |