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

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

Issue 477053002: Add a QuicSustainedBandwidthEstimator class. Not yet used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@re-add_DCHECK_to_ensure_packets_73128051
Patch Set: Created 6 years, 4 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
OLDNEW
(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, bandwidth, estimate_time, wall_time, srtt);
28 EXPECT_FALSE(recorder.HasEstimate());
29
30 // Send a second reading, again this should not result in a valid estimate,
31 // as not enough time has passed.
32 estimate_time = estimate_time.Add(srtt);
33 recorder.RecordEstimate(true, bandwidth, estimate_time, wall_time, srtt);
34 EXPECT_FALSE(recorder.HasEstimate());
35
36 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate.
37 estimate_time = estimate_time.Add(srtt);
38 estimate_time = estimate_time.Add(srtt);
39 recorder.RecordEstimate(true, bandwidth, estimate_time, wall_time, srtt);
40 EXPECT_TRUE(recorder.HasEstimate());
41 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth);
42 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate());
43
44 // Resetting, and sending a different estimate will only change output after
45 // a further 3 * kSRTT has passed.
46 QuicBandwidth second_bandwidth =
47 QuicBandwidth::FromBitsPerSecond(2 * kBandwidthBitsPerSecond);
48 // Reset the recorder by passing in an unreliable measurement.
49 recorder.RecordEstimate(false, second_bandwidth, estimate_time, wall_time,
50 srtt);
51 recorder.RecordEstimate(true, second_bandwidth, estimate_time, wall_time,
52 srtt);
53 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth);
54
55 estimate_time = estimate_time.Add(srtt.Multiply(3));
56 const int32 kSeconds = 556677;
57 QuicWallTime second_bandwidth_wall_time =
58 QuicWallTime::FromUNIXSeconds(kSeconds);
59 recorder.RecordEstimate(true, second_bandwidth, estimate_time,
60 second_bandwidth_wall_time, srtt);
61 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth);
62 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate());
63 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds);
64
65 // Reset again, this time recording a lower bandwidth than before.
66 QuicBandwidth third_bandwidth =
67 QuicBandwidth::FromBitsPerSecond(0.5 * kBandwidthBitsPerSecond);
68 // Reset the recorder by passing in an unreliable measurement.
69 recorder.RecordEstimate(false, third_bandwidth, estimate_time, wall_time,
70 srtt);
71 recorder.RecordEstimate(true, third_bandwidth, estimate_time, wall_time,
72 srtt);
73 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth);
74
75 estimate_time = estimate_time.Add(srtt.Multiply(3));
76 recorder.RecordEstimate(true, third_bandwidth, estimate_time, wall_time,
77 srtt);
78 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth);
79
80 // Max bandwidth should not have changed.
81 EXPECT_LT(third_bandwidth, second_bandwidth);
82 EXPECT_EQ(recorder.MaxBandwidthEstimate(), second_bandwidth);
83 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds);
84 }
85
86 } // namespace
87 } // namespace test
88 } // namespace net
OLDNEW
« net/quic/quic_sustained_bandwidth_recorder.h ('K') | « net/quic/quic_sustained_bandwidth_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698