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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/quic/quic_sustained_bandwidth_recorder_test.cc
diff --git a/net/quic/quic_sustained_bandwidth_recorder_test.cc b/net/quic/quic_sustained_bandwidth_recorder_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..060b9fab9495759e0c8b0ada161d856f87303ebd
--- /dev/null
+++ b/net/quic/quic_sustained_bandwidth_recorder_test.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/quic_sustained_bandwidth_recorder.h"
+
+#include "net/quic/quic_bandwidth.h"
+#include "net/quic/quic_time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+namespace test {
+namespace {
+
+TEST(QuicSustainedBandwidthRecorderTest, BandwidthEstimates) {
+ QuicSustainedBandwidthRecorder recorder;
+ EXPECT_FALSE(recorder.HasEstimate());
+
+ QuicTime estimate_time = QuicTime::Zero();
+ QuicWallTime wall_time = QuicWallTime::Zero();
+ QuicTime::Delta srtt = QuicTime::Delta::FromMilliseconds(150);
+ const int kBandwidthBitsPerSecond = 12345678;
+ QuicBandwidth bandwidth =
+ QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond);
+
+ // This triggers recording, but should not yield a valid estimate yet.
+ recorder.RecordEstimate(true, bandwidth, estimate_time, wall_time, srtt);
+ EXPECT_FALSE(recorder.HasEstimate());
+
+ // Send a second reading, again this should not result in a valid estimate,
+ // as not enough time has passed.
+ estimate_time = estimate_time.Add(srtt);
+ recorder.RecordEstimate(true, bandwidth, estimate_time, wall_time, srtt);
+ EXPECT_FALSE(recorder.HasEstimate());
+
+ // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate.
+ estimate_time = estimate_time.Add(srtt);
+ estimate_time = estimate_time.Add(srtt);
+ recorder.RecordEstimate(true, bandwidth, estimate_time, wall_time, srtt);
+ EXPECT_TRUE(recorder.HasEstimate());
+ EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth);
+ EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate());
+
+ // Resetting, and sending a different estimate will only change output after
+ // a further 3 * kSRTT has passed.
+ QuicBandwidth second_bandwidth =
+ QuicBandwidth::FromBitsPerSecond(2 * kBandwidthBitsPerSecond);
+ // Reset the recorder by passing in an unreliable measurement.
+ recorder.RecordEstimate(false, second_bandwidth, estimate_time, wall_time,
+ srtt);
+ recorder.RecordEstimate(true, second_bandwidth, estimate_time, wall_time,
+ srtt);
+ EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth);
+
+ estimate_time = estimate_time.Add(srtt.Multiply(3));
+ const int32 kSeconds = 556677;
+ QuicWallTime second_bandwidth_wall_time =
+ QuicWallTime::FromUNIXSeconds(kSeconds);
+ recorder.RecordEstimate(true, second_bandwidth, estimate_time,
+ second_bandwidth_wall_time, srtt);
+ EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth);
+ EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate());
+ EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds);
+
+ // Reset again, this time recording a lower bandwidth than before.
+ QuicBandwidth third_bandwidth =
+ QuicBandwidth::FromBitsPerSecond(0.5 * kBandwidthBitsPerSecond);
+ // Reset the recorder by passing in an unreliable measurement.
+ recorder.RecordEstimate(false, third_bandwidth, estimate_time, wall_time,
+ srtt);
+ recorder.RecordEstimate(true, third_bandwidth, estimate_time, wall_time,
+ srtt);
+ EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth);
+
+ estimate_time = estimate_time.Add(srtt.Multiply(3));
+ recorder.RecordEstimate(true, third_bandwidth, estimate_time, wall_time,
+ srtt);
+ EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth);
+
+ // Max bandwidth should not have changed.
+ EXPECT_LT(third_bandwidth, second_bandwidth);
+ EXPECT_EQ(recorder.MaxBandwidthEstimate(), second_bandwidth);
+ EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds);
+}
+
+} // namespace
+} // namespace test
+} // namespace net
« 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