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

Unified Diff: net/base/network_quality_estimator_unittest.cc

Issue 1672513002: Expose packet loss counts from QUIC to NetworkQualityEstimator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed rch comments Created 4 years, 9 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/base/network_quality_estimator_unittest.cc
diff --git a/net/base/network_quality_estimator_unittest.cc b/net/base/network_quality_estimator_unittest.cc
index 25e386db44db573184f628053115c75be6ea87e5..35a3e6a3b6a3f4f8ef03b02a0aa7ff8eb7e5e9cc 100644
--- a/net/base/network_quality_estimator_unittest.cc
+++ b/net/base/network_quality_estimator_unittest.cc
@@ -4,9 +4,12 @@
#include "net/base/network_quality_estimator.h"
+#include <stddef.h>
#include <stdint.h>
+
#include <limits>
#include <map>
+#include <string>
#include <utility>
#include <vector>
@@ -23,6 +26,7 @@
#include "net/base/external_estimate_provider.h"
#include "net/base/load_flags.h"
#include "net/base/network_change_notifier.h"
+#include "net/base/socket_performance_watcher_factory.h"
#include "net/http/http_status_code.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
@@ -157,6 +161,45 @@ class TestThroughputObserver
std::vector<Observation> observations_;
};
+class TestPacketCountObserver
+ : public net::NetworkQualityEstimator::PacketCountObserver {
+ public:
+ struct Observation {
+ Observation(size_t packets_missing,
+ size_t packets_received_in_order,
+ size_t packets_received_out_of_order,
+ const base::TimeTicks& ts,
+ net::NetworkQualityEstimator::ObservationSource src)
+ : packets_missing(packets_missing),
+ packets_received_in_order(packets_received_in_order),
+ packets_received_out_of_order(packets_received_out_of_order),
+ timestamp(ts),
+ source(src) {}
+ size_t packets_missing;
+ size_t packets_received_in_order;
+ size_t packets_received_out_of_order;
+ base::TimeTicks timestamp;
+ net::NetworkQualityEstimator::ObservationSource source;
+ };
+
+ std::vector<Observation>& observations() { return observations_; }
+
+ // PacketCountObserver implementation:
+ void OnIncrementalPacketCountObservation(
+ size_t packets_missing,
+ size_t packets_received_in_order,
+ size_t packets_received_out_of_order,
+ const base::TimeTicks& timestamp,
+ net::NetworkQualityEstimator::ObservationSource source) override {
+ observations_.push_back(
+ Observation(packets_missing, packets_received_in_order,
+ packets_received_out_of_order, timestamp, source));
+ }
+
+ private:
+ std::vector<Observation> observations_;
+};
+
} // namespace
namespace net {
@@ -536,9 +579,9 @@ TEST(NetworkQualityEstimatorTest, HalfLifeParam) {
// Half life parameter is not set. Default value of
// |weight_multiplier_per_second_| should be used.
TestNetworkQualityEstimator estimator(variation_params);
- EXPECT_NEAR(0.988, estimator.downstream_throughput_kbps_observations_
- .weight_multiplier_per_second_,
- 0.001);
+ EXPECT_NEAR(0.988f, estimator.downstream_throughput_kbps_observations_
+ .weight_multiplier_per_second_,
+ 0.001f);
}
variation_params["HalfLifeSeconds"] = "-100";
@@ -546,9 +589,9 @@ TEST(NetworkQualityEstimatorTest, HalfLifeParam) {
// Half life parameter is set to a negative value. Default value of
// |weight_multiplier_per_second_| should be used.
TestNetworkQualityEstimator estimator(variation_params);
- EXPECT_NEAR(0.988, estimator.downstream_throughput_kbps_observations_
- .weight_multiplier_per_second_,
- 0.001);
+ EXPECT_NEAR(0.988f, estimator.downstream_throughput_kbps_observations_
+ .weight_multiplier_per_second_,
+ 0.001f);
}
variation_params["HalfLifeSeconds"] = "0";
@@ -556,18 +599,18 @@ TEST(NetworkQualityEstimatorTest, HalfLifeParam) {
// Half life parameter is set to zero. Default value of
// |weight_multiplier_per_second_| should be used.
TestNetworkQualityEstimator estimator(variation_params);
- EXPECT_NEAR(0.988, estimator.downstream_throughput_kbps_observations_
- .weight_multiplier_per_second_,
- 0.001);
+ EXPECT_NEAR(0.988f, estimator.downstream_throughput_kbps_observations_
+ .weight_multiplier_per_second_,
+ 0.001f);
}
variation_params["HalfLifeSeconds"] = "10";
{
// Half life parameter is set to a valid value.
TestNetworkQualityEstimator estimator(variation_params);
- EXPECT_NEAR(0.933, estimator.downstream_throughput_kbps_observations_
- .weight_multiplier_per_second_,
- 0.001);
+ EXPECT_NEAR(0.933f, estimator.downstream_throughput_kbps_observations_
+ .weight_multiplier_per_second_,
+ 0.001f);
}
}
@@ -1026,10 +1069,12 @@ TEST(NetworkQualityEstimatorTest, TestExternalEstimateProviderMergeEstimates) {
TEST(NetworkQualityEstimatorTest, TestObservers) {
TestRTTObserver rtt_observer;
TestThroughputObserver throughput_observer;
+ TestPacketCountObserver packet_count_observer;
std::map<std::string, std::string> variation_params;
TestNetworkQualityEstimator estimator(variation_params);
estimator.AddRTTObserver(&rtt_observer);
estimator.AddThroughputObserver(&throughput_observer);
+ estimator.AddPacketCountObserver(&packet_count_observer);
TestDelegate test_delegate;
TestURLRequestContext context(true);
@@ -1052,6 +1097,9 @@ TEST(NetworkQualityEstimatorTest, TestObservers) {
request2->Start();
base::RunLoop().Run();
+ estimator.OnIncrementalPacketCountAvailable(
+ NetworkQualityEstimator::PROTOCOL_QUIC, 0, 1, 1);
+
// Both RTT and downstream throughput should be updated.
EXPECT_NE(NetworkQualityEstimator::InvalidRTT(),
estimator.GetRTTEstimateInternal(base::TimeTicks(), 100));
@@ -1061,16 +1109,24 @@ TEST(NetworkQualityEstimatorTest, TestObservers) {
EXPECT_EQ(2U, rtt_observer.observations().size());
EXPECT_EQ(2U, throughput_observer.observations().size());
- for (auto observation : rtt_observer.observations()) {
+ ASSERT_EQ(1U, packet_count_observer.observations().size());
+ for (const auto& observation : rtt_observer.observations()) {
EXPECT_LE(0, observation.rtt_ms);
EXPECT_LE(0, (observation.timestamp - then).InMilliseconds());
EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source);
}
- for (auto observation : throughput_observer.observations()) {
+ for (const auto& observation : throughput_observer.observations()) {
EXPECT_LE(0, observation.throughput_kbps);
EXPECT_LE(0, (observation.timestamp - then).InMilliseconds());
EXPECT_EQ(NetworkQualityEstimator::URL_REQUEST, observation.source);
}
+ for (const auto& observation : packet_count_observer.observations()) {
+ EXPECT_LE(0u, observation.packets_missing);
+ EXPECT_LE(1u, observation.packets_received_in_order);
+ EXPECT_LE(0u, observation.packets_received_out_of_order);
+ EXPECT_LE(0, (observation.timestamp - then).InMilliseconds());
+ EXPECT_EQ(NetworkQualityEstimator::QUIC, observation.source);
+ }
// Verify that observations from TCP and QUIC are passed on to the observers.
base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1));

Powered by Google App Engine
This is Rietveld 408576698