Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: net/quic/quic_sustained_bandwidth_recorder_test.cc

Issue 2125303002: Use overloaded operators with QuicTime for addition, subtraction and scalar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@126402784
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_sustained_bandwidth_recorder.cc ('k') | net/quic/quic_time.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_sustained_bandwidth_recorder.h" 5 #include "net/quic/quic_sustained_bandwidth_recorder.h"
6 6
7 #include "net/quic/quic_bandwidth.h" 7 #include "net/quic/quic_bandwidth.h"
8 #include "net/quic/quic_time.h" 8 #include "net/quic/quic_time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 15 matching lines...) Expand all
26 bool in_recovery = false; 26 bool in_recovery = false;
27 bool in_slow_start = false; 27 bool in_slow_start = false;
28 28
29 // This triggers recording, but should not yield a valid estimate yet. 29 // This triggers recording, but should not yield a valid estimate yet.
30 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 30 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
31 wall_time, srtt); 31 wall_time, srtt);
32 EXPECT_FALSE(recorder.HasEstimate()); 32 EXPECT_FALSE(recorder.HasEstimate());
33 33
34 // Send a second reading, again this should not result in a valid estimate, 34 // Send a second reading, again this should not result in a valid estimate,
35 // as not enough time has passed. 35 // as not enough time has passed.
36 estimate_time = estimate_time.Add(srtt); 36 estimate_time = estimate_time + srtt;
37 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 37 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
38 wall_time, srtt); 38 wall_time, srtt);
39 EXPECT_FALSE(recorder.HasEstimate()); 39 EXPECT_FALSE(recorder.HasEstimate());
40 40
41 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. 41 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate.
42 estimate_time = estimate_time.Add(srtt); 42 estimate_time = estimate_time + srtt;
43 estimate_time = estimate_time.Add(srtt); 43 estimate_time = estimate_time + srtt;
44 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 44 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
45 wall_time, srtt); 45 wall_time, srtt);
46 EXPECT_TRUE(recorder.HasEstimate()); 46 EXPECT_TRUE(recorder.HasEstimate());
47 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); 47 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth);
48 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); 48 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate());
49 49
50 // Resetting, and sending a different estimate will only change output after 50 // Resetting, and sending a different estimate will only change output after
51 // a further 3 * kSRTT has passed. 51 // a further 3 * kSRTT has passed.
52 QuicBandwidth second_bandwidth = 52 QuicBandwidth second_bandwidth =
53 QuicBandwidth::FromBitsPerSecond(2 * kBandwidthBitsPerSecond); 53 QuicBandwidth::FromBitsPerSecond(2 * kBandwidthBitsPerSecond);
54 // Reset the recorder by passing in a measurement while in recovery. 54 // Reset the recorder by passing in a measurement while in recovery.
55 in_recovery = true; 55 in_recovery = true;
56 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 56 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
57 wall_time, srtt); 57 wall_time, srtt);
58 in_recovery = false; 58 in_recovery = false;
59 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 59 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
60 wall_time, srtt); 60 wall_time, srtt);
61 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); 61 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth);
62 62
63 estimate_time = estimate_time.Add(srtt.Multiply(3)); 63 estimate_time = estimate_time + 3 * srtt;
64 const int64_t kSeconds = 556677; 64 const int64_t kSeconds = 556677;
65 QuicWallTime second_bandwidth_wall_time = 65 QuicWallTime second_bandwidth_wall_time =
66 QuicWallTime::FromUNIXSeconds(kSeconds); 66 QuicWallTime::FromUNIXSeconds(kSeconds);
67 recorder.RecordEstimate(in_recovery, in_slow_start, second_bandwidth, 67 recorder.RecordEstimate(in_recovery, in_slow_start, second_bandwidth,
68 estimate_time, second_bandwidth_wall_time, srtt); 68 estimate_time, second_bandwidth_wall_time, srtt);
69 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth); 69 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth);
70 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); 70 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate());
71 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); 71 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds);
72 72
73 // Reset again, this time recording a lower bandwidth than before. 73 // Reset again, this time recording a lower bandwidth than before.
74 QuicBandwidth third_bandwidth = 74 QuicBandwidth third_bandwidth =
75 QuicBandwidth::FromBitsPerSecond(0.5 * kBandwidthBitsPerSecond); 75 QuicBandwidth::FromBitsPerSecond(0.5 * kBandwidthBitsPerSecond);
76 // Reset the recorder by passing in an unreliable measurement. 76 // Reset the recorder by passing in an unreliable measurement.
77 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth, 77 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth,
78 estimate_time, wall_time, srtt); 78 estimate_time, wall_time, srtt);
79 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth, 79 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth,
80 estimate_time, wall_time, srtt); 80 estimate_time, wall_time, srtt);
81 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth); 81 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth);
82 82
83 estimate_time = estimate_time.Add(srtt.Multiply(3)); 83 estimate_time = estimate_time + 3 * srtt;
84 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth, 84 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth,
85 estimate_time, wall_time, srtt); 85 estimate_time, wall_time, srtt);
86 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth); 86 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth);
87 87
88 // Max bandwidth should not have changed. 88 // Max bandwidth should not have changed.
89 EXPECT_LT(third_bandwidth, second_bandwidth); 89 EXPECT_LT(third_bandwidth, second_bandwidth);
90 EXPECT_EQ(recorder.MaxBandwidthEstimate(), second_bandwidth); 90 EXPECT_EQ(recorder.MaxBandwidthEstimate(), second_bandwidth);
91 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); 91 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds);
92 } 92 }
93 93
(...skipping 10 matching lines...) Expand all
104 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond); 104 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond);
105 105
106 bool in_recovery = false; 106 bool in_recovery = false;
107 bool in_slow_start = true; 107 bool in_slow_start = true;
108 108
109 // This triggers recording, but should not yield a valid estimate yet. 109 // This triggers recording, but should not yield a valid estimate yet.
110 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 110 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
111 wall_time, srtt); 111 wall_time, srtt);
112 112
113 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. 113 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate.
114 estimate_time = estimate_time.Add(srtt.Multiply(3)); 114 estimate_time = estimate_time + 3 * srtt;
115 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 115 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
116 wall_time, srtt); 116 wall_time, srtt);
117 EXPECT_TRUE(recorder.HasEstimate()); 117 EXPECT_TRUE(recorder.HasEstimate());
118 EXPECT_TRUE(recorder.EstimateRecordedDuringSlowStart()); 118 EXPECT_TRUE(recorder.EstimateRecordedDuringSlowStart());
119 119
120 // Now send another estimate, this time not in slow start. 120 // Now send another estimate, this time not in slow start.
121 estimate_time = estimate_time.Add(srtt.Multiply(3)); 121 estimate_time = estimate_time + 3 * srtt;
122 in_slow_start = false; 122 in_slow_start = false;
123 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, 123 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time,
124 wall_time, srtt); 124 wall_time, srtt);
125 EXPECT_TRUE(recorder.HasEstimate()); 125 EXPECT_TRUE(recorder.HasEstimate());
126 EXPECT_FALSE(recorder.EstimateRecordedDuringSlowStart()); 126 EXPECT_FALSE(recorder.EstimateRecordedDuringSlowStart());
127 } 127 }
128 128
129 } // namespace 129 } // namespace
130 } // namespace test 130 } // namespace test
131 } // namespace net 131 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_sustained_bandwidth_recorder.cc ('k') | net/quic/quic_time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698