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

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

Issue 2221103003: Compute effective connection type dynamically (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 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
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 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 "test"); 1527 "test");
1528 EXPECT_EQ(2U, observer.effective_connection_types().size()); 1528 EXPECT_EQ(2U, observer.effective_connection_types().size());
1529 1529
1530 // A change in effective connection type does not trigger notification to the 1530 // A change in effective connection type does not trigger notification to the
1531 // observers, since it is not accompanied by any new observation or a network 1531 // observers, since it is not accompanied by any new observation or a network
1532 // change event. 1532 // change event.
1533 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); 1533 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
1534 EXPECT_EQ(2U, observer.effective_connection_types().size()); 1534 EXPECT_EQ(2U, observer.effective_connection_types().size());
1535 } 1535 }
1536 1536
1537 // Tests that the effective connection type is computed on every RTT
1538 // observation if the last computed effective connection type was unknown.
1539 TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) {
1540 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1541 new base::SimpleTestTickClock());
1542 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
1543
1544 TestEffectiveConnectionTypeObserver observer;
1545 std::map<std::string, std::string> variation_params;
1546 TestNetworkQualityEstimator estimator(variation_params);
1547 estimator.SetTickClockForTesting(std::move(tick_clock));
1548 estimator.AddEffectiveConnectionTypeObserver(&observer);
1549 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1550
1551 size_t expected_effective_connection_type_notifications = 0;
1552 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1553 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
1554 "test");
1555
1556 NetworkQualityEstimator::RttObservation rtt_observation(
1557 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
1558 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST);
1559
1560 for (size_t i = 0; i < 10; ++i) {
1561 estimator.NotifyObserversOfRTT(rtt_observation);
1562 EXPECT_EQ(expected_effective_connection_type_notifications,
1563 observer.effective_connection_types().size());
1564 }
1565 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1566 // Even though there are 10 RTT samples already available, addition of one
bengr 2016/08/09 21:29:06 addition -> the addition
tbansal1 2016/08/10 00:13:12 Done.
1567 // more RTT sample should trigger recomputation of effective connection type
bengr 2016/08/09 21:29:06 of -> of the
tbansal1 2016/08/10 00:13:12 Done.
1568 // since the last computed effective connection type was unknown.
1569 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation(
1570 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
1571 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
1572 ++expected_effective_connection_type_notifications;
1573 EXPECT_EQ(expected_effective_connection_type_notifications,
1574 observer.effective_connection_types().size());
1575 }
1576
1577 // Tests that the effective connection type is computed regularly depending
1578 // on the number of RTT and bandwidth samples.
1579 TEST(NetworkQualityEstimatorTest,
1580 AdaptiveRecomputationEffectiveConnectionType) {
1581 base::HistogramTester histogram_tester;
1582 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1583 new base::SimpleTestTickClock());
1584 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
1585
1586 TestEffectiveConnectionTypeObserver observer;
1587 std::map<std::string, std::string> variation_params;
1588 TestNetworkQualityEstimator estimator(variation_params);
1589 estimator.SetTickClockForTesting(std::move(tick_clock));
1590 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
1591 "test");
1592 estimator.AddEffectiveConnectionTypeObserver(&observer);
1593
1594 TestDelegate test_delegate;
1595 TestURLRequestContext context(true);
1596 context.set_network_quality_estimator(&estimator);
1597 context.Init();
1598
1599 EXPECT_EQ(0U, observer.effective_connection_types().size());
1600
1601 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
1602 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1603
1604 std::unique_ptr<URLRequest> request(context.CreateRequest(
1605 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1606 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME);
1607 request->Start();
1608 base::RunLoop().Run();
1609 EXPECT_EQ(1U, observer.effective_connection_types().size());
1610 histogram_tester.ExpectUniqueSample(
1611 "NQE.MainFrame.EffectiveConnectionType.WiFi",
1612 EFFECTIVE_CONNECTION_TYPE_2G, 1);
1613
1614 size_t expected_effective_connection_type_notifications = 1;
1615 EXPECT_EQ(expected_effective_connection_type_notifications,
1616 observer.effective_connection_types().size());
1617
1618 EXPECT_EQ(expected_effective_connection_type_notifications,
1619 estimator.rtt_observations_.Size());
1620
1621 // Increase the number of RTT observations. Every time the number of RTT
1622 // observations are more than doubled, effective connection type must be
bengr 2016/08/09 21:29:06 are -> is
tbansal1 2016/08/10 00:13:12 Done.
1623 // recomputed, and notified to observers.
bengr 2016/08/09 21:29:06 recomputed, -> recomputed
tbansal1 2016/08/10 00:13:12 Done.
1624 for (size_t repetition = 0; repetition < 2; ++repetition) {
1625 // Change the effective connection type so that the observers are
1626 // notified when the effective connection type is recomputed.
1627 if (repetition % 2 == 0) {
1628 estimator.set_effective_connection_type(
1629 EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1630 } else {
1631 estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
1632 }
1633 size_t rtt_observations_count = estimator.rtt_observations_.Size();
1634 // Increase the number of RTT observations to more than twice the number
bengr 2016/08/09 21:29:06 Do you also test that not increasing the number do
tbansal1 2016/08/10 00:13:12 I am not sure if I understand this comment. I am c
bengr 2016/08/12 18:52:36 Never mind. I see you covered the case I was worri
1635 // of current observations. This should trigger recomputation of
1636 // effective connection type.
1637 for (size_t i = 0; i < rtt_observations_count + 1; ++i) {
1638 estimator.rtt_observations_.AddObservation(
1639 NetworkQualityEstimator::RttObservation(
1640 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
1641 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
1642
1643 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation(
1644 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(),
1645 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST));
1646
1647 if (i == rtt_observations_count) {
1648 // Effective connection type must be recomputed since the number of RTT
1649 // samples are now more than twice the number of RTT samples that were
1650 // available when effective connection type was last computed.
1651 ++expected_effective_connection_type_notifications;
1652 }
1653 EXPECT_EQ(expected_effective_connection_type_notifications,
1654 observer.effective_connection_types().size());
1655 }
1656 }
1657 }
1658
1537 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { 1659 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) {
1538 TestRTTObserver rtt_observer; 1660 TestRTTObserver rtt_observer;
1539 TestThroughputObserver throughput_observer; 1661 TestThroughputObserver throughput_observer;
1540 std::map<std::string, std::string> variation_params; 1662 std::map<std::string, std::string> variation_params;
1541 TestNetworkQualityEstimator estimator(variation_params); 1663 TestNetworkQualityEstimator estimator(variation_params);
1542 estimator.AddRTTObserver(&rtt_observer); 1664 estimator.AddRTTObserver(&rtt_observer);
1543 estimator.AddThroughputObserver(&throughput_observer); 1665 estimator.AddThroughputObserver(&throughput_observer);
1544 1666
1545 TestDelegate test_delegate; 1667 TestDelegate test_delegate;
1546 TestURLRequestContext context(true); 1668 TestURLRequestContext context(true);
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 2168
2047 // Get the bits at index 18-24 which contain the resource fetch time. 2169 // Get the bits at index 18-24 which contain the resource fetch time.
2048 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); 2170 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128);
2049 2171
2050 // Get the bits at index 25-31 which contain the resource load size. 2172 // Get the bits at index 25-31 which contain the resource load size.
2051 EXPECT_LE(0, (buckets.at(0).min) % 128); 2173 EXPECT_LE(0, (buckets.at(0).min) % 128);
2052 } 2174 }
2053 } 2175 }
2054 2176
2055 } // namespace net 2177 } // namespace net
OLDNEW
« net/nqe/network_quality_estimator.h ('K') | « net/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698