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

Side by Side Diff: net/nqe/network_quality_estimator_unittest.cc

Issue 2712443002: NQE: Move ECT computation to NotifyHeadersReceived (Closed)
Patch Set: Created 3 years, 10 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/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/nqe/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 // interval, and that the observers are notified of any change. 1560 // interval, and that the observers are notified of any change.
1561 TEST(NetworkQualityEstimatorTest, MAYBE_TestEffectiveConnectionTypeObserver) { 1561 TEST(NetworkQualityEstimatorTest, MAYBE_TestEffectiveConnectionTypeObserver) {
1562 base::HistogramTester histogram_tester; 1562 base::HistogramTester histogram_tester;
1563 std::unique_ptr<base::SimpleTestTickClock> tick_clock( 1563 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1564 new base::SimpleTestTickClock()); 1564 new base::SimpleTestTickClock());
1565 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); 1565 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
1566 1566
1567 TestEffectiveConnectionTypeObserver observer; 1567 TestEffectiveConnectionTypeObserver observer;
1568 TestNetworkQualityEstimator estimator; 1568 TestNetworkQualityEstimator estimator;
1569 estimator.AddEffectiveConnectionTypeObserver(&observer); 1569 estimator.AddEffectiveConnectionTypeObserver(&observer);
1570 // |observer| may be notified as soon as it is added. Run the loop to so that
1571 // the notification to |observer| is finished.
1572 base::RunLoop().RunUntilIdle();
1570 estimator.SetTickClockForTesting(std::move(tick_clock)); 1573 estimator.SetTickClockForTesting(std::move(tick_clock));
1571 1574
1572 TestDelegate test_delegate; 1575 TestDelegate test_delegate;
1573 TestURLRequestContext context(true); 1576 TestURLRequestContext context(true);
1574 context.set_network_quality_estimator(&estimator); 1577 context.set_network_quality_estimator(&estimator);
1575 context.Init(); 1578 context.Init();
1576 1579
1577 EXPECT_EQ(0U, observer.effective_connection_types().size()); 1580 EXPECT_EQ(0U, observer.effective_connection_types().size());
1578 1581
1579 estimator.set_start_time_null_http_rtt( 1582 estimator.set_start_time_null_http_rtt(
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 std::unique_ptr<base::SimpleTestTickClock> tick_clock( 1788 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1786 new base::SimpleTestTickClock()); 1789 new base::SimpleTestTickClock());
1787 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); 1790 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
1788 1791
1789 TestEffectiveConnectionTypeObserver observer; 1792 TestEffectiveConnectionTypeObserver observer;
1790 TestNetworkQualityEstimator estimator; 1793 TestNetworkQualityEstimator estimator;
1791 estimator.SetTickClockForTesting(std::move(tick_clock)); 1794 estimator.SetTickClockForTesting(std::move(tick_clock));
1792 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, 1795 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI,
1793 "test"); 1796 "test");
1794 estimator.AddEffectiveConnectionTypeObserver(&observer); 1797 estimator.AddEffectiveConnectionTypeObserver(&observer);
1798 // |observer| may be notified as soon as it is added. Run the loop to so that
1799 // the notification to |observer| is finished.
1800 base::RunLoop().RunUntilIdle();
1795 1801
1796 TestDelegate test_delegate; 1802 TestDelegate test_delegate;
1797 TestURLRequestContext context(true); 1803 TestURLRequestContext context(true);
1798 context.set_network_quality_estimator(&estimator); 1804 context.set_network_quality_estimator(&estimator);
1799 context.Init(); 1805 context.Init();
1800 1806
1801 EXPECT_EQ(0U, observer.effective_connection_types().size()); 1807 EXPECT_EQ(0U, observer.effective_connection_types().size());
1802 1808
1803 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); 1809 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
1804 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); 1810 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 #if defined(TCP_INFO) || defined(OS_LINUX) 1958 #if defined(TCP_INFO) || defined(OS_LINUX)
1953 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT 1959 #define MAYBE_TestTCPSocketRTT TestTCPSocketRTT
1954 #else 1960 #else
1955 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT 1961 #define MAYBE_TestTCPSocketRTT DISABLED_TestTCPSocketRTT
1956 #endif 1962 #endif
1957 // Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs, 1963 // Tests that the TCP socket notifies the Network Quality Estimator of TCP RTTs,
1958 // which in turn notifies registered RTT observers. 1964 // which in turn notifies registered RTT observers.
1959 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { 1965 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
1960 base::HistogramTester histogram_tester; 1966 base::HistogramTester histogram_tester;
1961 TestRTTObserver rtt_observer; 1967 TestRTTObserver rtt_observer;
1962 TestNetworkQualityEstimator estimator; 1968
1969 std::map<std::string, std::string> variation_params;
1970 variation_params["persistent_cache_reading_enabled"] = "true";
1971 TestNetworkQualityEstimator estimator(
1972 nullptr, variation_params, true, true,
1973 true /* add_default_platform_observations */);
1974 estimator.SimulateNetworkChange(
1975 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
1976
1963 estimator.AddRTTObserver(&rtt_observer); 1977 estimator.AddRTTObserver(&rtt_observer);
1978 // |observer| may be notified as soon as it is added. Run the loop to so that
1979 // the notification to |observer| is finished.
1980 base::RunLoop().RunUntilIdle();
1964 1981
1965 TestDelegate test_delegate; 1982 TestDelegate test_delegate;
1966 TestURLRequestContext context(true); 1983 TestURLRequestContext context(true);
1967 context.set_network_quality_estimator(&estimator); 1984 context.set_network_quality_estimator(&estimator);
1968 1985
1969 std::unique_ptr<HttpNetworkSession::Params> params( 1986 std::unique_ptr<HttpNetworkSession::Params> params(
1970 new HttpNetworkSession::Params); 1987 new HttpNetworkSession::Params);
1971 // |estimator| should be notified of TCP RTT observations. 1988 // |estimator| should be notified of TCP RTT observations.
1972 params->socket_performance_watcher_factory = 1989 params->socket_performance_watcher_factory =
1973 estimator.GetSocketPerformanceWatcherFactory(); 1990 estimator.GetSocketPerformanceWatcherFactory();
1974 context.set_http_network_session_params(std::move(params)); 1991 context.set_http_network_session_params(std::move(params));
1975 context.Init(); 1992 context.Init();
1976 1993
1977 EXPECT_EQ(0U, rtt_observer.observations().size()); 1994 EXPECT_EQ(0U, rtt_observer.observations().size());
1978 base::TimeDelta rtt; 1995 base::TimeDelta rtt;
1979 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 1996 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
1980 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); 1997 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
1981 1998
1982 // Send two requests. Verify that the completion of each request generates at 1999 // Send two requests. Verify that the completion of each request generates at
1983 // least one TCP RTT observation. 2000 // least one TCP RTT observation.
1984 const size_t num_requests = 2; 2001 const size_t num_requests = 2;
1985 for (size_t i = 0; i < num_requests; ++i) { 2002 for (size_t i = 0; i < num_requests; ++i) {
1986 size_t before_count_tcp_rtt_observations = 0; 2003 size_t before_count_tcp_rtt_observations = 0;
1987 for (const auto& observation : rtt_observer.observations()) { 2004 for (const auto& observation : rtt_observer.observations()) {
1988 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) 2005 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)
1989 ++before_count_tcp_rtt_observations; 2006 ++before_count_tcp_rtt_observations;
1990 } 2007 }
(...skipping 13 matching lines...) Expand all
2004 // watcher. 2021 // watcher.
2005 EXPECT_LE(1U, after_count_tcp_rtt_observations - 2022 EXPECT_LE(1U, after_count_tcp_rtt_observations -
2006 before_count_tcp_rtt_observations) 2023 before_count_tcp_rtt_observations)
2007 << i; 2024 << i;
2008 } 2025 }
2009 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 2026 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
2010 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); 2027 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
2011 2028
2012 estimator.SimulateNetworkChange( 2029 estimator.SimulateNetworkChange(
2013 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); 2030 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
2014 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); 2031 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.2G", 1);
2015 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.Unknown", 2032 histogram_tester.ExpectBucketCount("NQE.TransportRTT.Percentile50.2G",
2016 rtt.InMilliseconds(), 1); 2033 rtt.InMilliseconds(), 1);
2017 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); 2034 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.2G", 1);
2018 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); 2035 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.2G", 1);
2019 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); 2036 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.2G", 1);
2020 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", 2037 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.2G", 1);
2021 1);
2022 2038
2023 // Verify that metrics are logged correctly on main-frame requests. 2039 // Verify that metrics are logged correctly on main-frame requests.
2024 histogram_tester.ExpectTotalCount("NQE.MainFrame.TransportRTT.Percentile50", 2040 histogram_tester.ExpectTotalCount("NQE.MainFrame.TransportRTT.Percentile50",
2025 num_requests); 2041 num_requests);
2026 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 0, 2042 histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.RTT", 1,
2027 1); 2043 num_requests);
2028 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1,
2029 num_requests - 1);
2030 histogram_tester.ExpectUniqueSample( 2044 histogram_tester.ExpectUniqueSample(
2031 "NQE.EstimateAvailable.MainFrame.TransportRTT", 1, num_requests); 2045 "NQE.EstimateAvailable.MainFrame.TransportRTT", 1, num_requests);
2032 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 0, 2046 histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.Kbps", 1,
2033 1); 2047 num_requests);
2034 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 1,
2035 num_requests - 1);
2036 2048
2037 histogram_tester.ExpectTotalCount( 2049 histogram_tester.ExpectTotalCount(
2038 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); 2050 "NQE.MainFrame.TransportRTT.Percentile50.2G", num_requests);
2039 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 2051 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType",
2040 num_requests); 2052 num_requests);
2041 histogram_tester.ExpectTotalCount( 2053 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType.2G",
2042 "NQE.MainFrame.EffectiveConnectionType.Unknown", num_requests); 2054 num_requests);
2043 histogram_tester.ExpectBucketCount( 2055 histogram_tester.ExpectBucketCount("NQE.MainFrame.EffectiveConnectionType.2G",
2044 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2056 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 0);
2045 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1);
2046 } 2057 }
2047 2058
2048 #if defined(OS_IOS) 2059 #if defined(OS_IOS)
2049 // Flaky on iOS when |accuracy_recording_delay| is non-zero. 2060 // Flaky on iOS when |accuracy_recording_delay| is non-zero.
2050 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy 2061 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy
2051 #else 2062 #else
2052 #define MAYBE_RecordAccuracy RecordAccuracy 2063 #define MAYBE_RecordAccuracy RecordAccuracy
2053 #endif 2064 #endif
2054 // Tests if the NQE accuracy metrics are recorded properly. 2065 // Tests if the NQE accuracy metrics are recorded properly.
2055 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) { 2066 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 estimator.set_recent_http_rtt(test.http_rtt); 2383 estimator.set_recent_http_rtt(test.http_rtt);
2373 estimator.set_start_time_null_downlink_throughput_kbps( 2384 estimator.set_start_time_null_downlink_throughput_kbps(
2374 test.downstream_throughput_kbps); 2385 test.downstream_throughput_kbps);
2375 estimator.set_rand_double(test.rand_double); 2386 estimator.set_rand_double(test.rand_double);
2376 2387
2377 TestDelegate test_delegate; 2388 TestDelegate test_delegate;
2378 TestURLRequestContext context(true); 2389 TestURLRequestContext context(true);
2379 context.set_network_quality_estimator(&estimator); 2390 context.set_network_quality_estimator(&estimator);
2380 context.Init(); 2391 context.Init();
2381 2392
2393 histogram_tester.ExpectTotalCount(
2394 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0);
2395
2382 // Start a main-frame request that should cause network quality estimator to 2396 // Start a main-frame request that should cause network quality estimator to
2383 // record the network quality at the last main frame request. 2397 // record the network quality at the last main frame request.
2384 std::unique_ptr<URLRequest> request_1(context.CreateRequest( 2398 std::unique_ptr<URLRequest> request_1(context.CreateRequest(
2385 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 2399 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
2386 request_1->SetLoadFlags(request_1->load_flags() | 2400 request_1->SetLoadFlags(request_1->load_flags() |
2387 LOAD_MAIN_FRAME_DEPRECATED); 2401 LOAD_MAIN_FRAME_DEPRECATED);
2388 request_1->Start(); 2402 request_1->Start();
2389 base::RunLoop().Run(); 2403 base::RunLoop().Run();
2390 histogram_tester.ExpectTotalCount(
2391 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0);
2392
2393 // Start another main-frame request which should cause network quality
2394 // estimator to record the correlation UMA.
2395 std::unique_ptr<URLRequest> request_2(context.CreateRequest(
2396 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
2397 request_2->Start();
2398 base::RunLoop().Run();
2399 2404
2400 if (test.rand_double >= test.correlation_logging_probability) { 2405 if (test.rand_double >= test.correlation_logging_probability) {
2401 histogram_tester.ExpectTotalCount( 2406 histogram_tester.ExpectTotalCount(
2402 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); 2407 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0);
2403 continue; 2408 continue;
2404 } 2409 }
2405 if (!test.use_transport_rtt && 2410 if (!test.use_transport_rtt &&
2406 test.http_rtt == nqe::internal::InvalidRTT()) { 2411 test.http_rtt == nqe::internal::InvalidRTT()) {
2407 histogram_tester.ExpectTotalCount( 2412 histogram_tester.ExpectTotalCount(
2408 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); 2413 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 ForceEffectiveConnectionTypeThroughFieldTrial) { 2551 ForceEffectiveConnectionTypeThroughFieldTrial) {
2547 for (int i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { 2552 for (int i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
2548 std::map<std::string, std::string> variation_params; 2553 std::map<std::string, std::string> variation_params;
2549 variation_params["force_effective_connection_type"] = 2554 variation_params["force_effective_connection_type"] =
2550 GetNameForEffectiveConnectionType( 2555 GetNameForEffectiveConnectionType(
2551 static_cast<EffectiveConnectionType>(i)); 2556 static_cast<EffectiveConnectionType>(i));
2552 TestNetworkQualityEstimator estimator(variation_params); 2557 TestNetworkQualityEstimator estimator(variation_params);
2553 2558
2554 TestEffectiveConnectionTypeObserver observer; 2559 TestEffectiveConnectionTypeObserver observer;
2555 estimator.AddEffectiveConnectionTypeObserver(&observer); 2560 estimator.AddEffectiveConnectionTypeObserver(&observer);
2561 // |observer| may be notified as soon as it is added. Run the loop to so
2562 // that the notification to |observer| is finished.
2563 base::RunLoop().RunUntilIdle();
2556 2564
2557 TestDelegate test_delegate; 2565 TestDelegate test_delegate;
2558 TestURLRequestContext context(true); 2566 TestURLRequestContext context(true);
2559 context.set_network_quality_estimator(&estimator); 2567 context.set_network_quality_estimator(&estimator);
2560 context.Init(); 2568 context.Init();
2561 2569
2562 EXPECT_EQ(0U, observer.effective_connection_types().size()); 2570 EXPECT_EQ(0U, observer.effective_connection_types().size());
2563 2571
2564 std::unique_ptr<URLRequest> request(context.CreateRequest( 2572 std::unique_ptr<URLRequest> request(context.CreateRequest(
2565 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 2573 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
2893 2901
2894 // Cleanup. 2902 // Cleanup.
2895 estimator.RemoveRTTObserver(&rtt_observer); 2903 estimator.RemoveRTTObserver(&rtt_observer);
2896 estimator.RemoveThroughputObserver(&throughput_observer); 2904 estimator.RemoveThroughputObserver(&throughput_observer);
2897 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); 2905 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer);
2898 estimator.RemoveEffectiveConnectionTypeObserver( 2906 estimator.RemoveEffectiveConnectionTypeObserver(
2899 &effective_connection_type_observer); 2907 &effective_connection_type_observer);
2900 } 2908 }
2901 2909
2902 } // namespace net 2910 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698