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

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

Issue 2113363002: NQE: Add Transport RTT based GetECT algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm 629 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm
630 expected_algorithm; 630 expected_algorithm;
631 } tests[] = { 631 } tests[] = {
632 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: 632 {false, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm::
633 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, 633 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT},
634 {true, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: 634 {true, "", NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm::
635 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, 635 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT},
636 {true, "HttpRTTAndDownstreamThroughput", 636 {true, "HttpRTTAndDownstreamThroughput",
637 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm:: 637 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm::
638 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, 638 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT},
639 {true, "TransportRTTOrDownstreamThroughput",
640 NetworkQualityEstimator::EffectiveConnectionTypeAlgorithm::
641 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT},
639 }; 642 };
640 643
641 for (const auto& test : tests) { 644 for (const auto& test : tests) {
642 std::map<std::string, std::string> variation_params; 645 std::map<std::string, std::string> variation_params;
643 if (test.set_variation_param) 646 if (test.set_variation_param)
644 variation_params["effective_connection_type_algorithm"] = test.algorithm; 647 variation_params["effective_connection_type_algorithm"] = test.algorithm;
645 648
646 TestNetworkQualityEstimator estimator(variation_params); 649 TestNetworkQualityEstimator estimator(variation_params);
647 EXPECT_EQ(test.expected_algorithm, 650 EXPECT_EQ(test.expected_algorithm,
648 estimator.effective_connection_type_algorithm_) 651 estimator.effective_connection_type_algorithm_)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); 750 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec));
748 estimator.set_recent_http_rtt( 751 estimator.set_recent_http_rtt(
749 base::TimeDelta::FromMilliseconds(test.rtt_msec)); 752 base::TimeDelta::FromMilliseconds(test.rtt_msec));
750 estimator.set_downlink_throughput_kbps(INT32_MAX); 753 estimator.set_downlink_throughput_kbps(INT32_MAX);
751 estimator.set_recent_downlink_throughput_kbps(INT32_MAX); 754 estimator.set_recent_downlink_throughput_kbps(INT32_MAX);
752 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 755 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
753 } 756 }
754 } 757 }
755 758
756 // Tests that |GetEffectiveConnectionType| returns correct connection type when 759 // Tests that |GetEffectiveConnectionType| returns correct connection type when
757 // both RTT and throughput thresholds are specified in the variation params. 760 // only transport RTT thresholds are specified in the variation params.
758 TEST(NetworkQualityEstimatorTest, ObtainThresholdsRTTandThroughput) { 761 TEST(NetworkQualityEstimatorTest, ObtainThresholdsOnlyTransportRTT) {
762 std::map<std::string, std::string> variation_params;
763 variation_params["effective_connection_type_algorithm"] =
764 "TransportRTTOrDownstreamThroughput";
765
766 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000";
767 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000";
768 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000";
769 variation_params["3G.ThresholdMedianTransportRTTMsec"] = "500";
770 variation_params["4G.ThresholdMedianTransportRTTMsec"] = "300";
771 variation_params["Broadband.ThresholdMedianTransportRTTMsec"] = "100";
772
773 TestNetworkQualityEstimator estimator(variation_params);
774
775 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType
776 // does not return Offline if the device is offline.
777 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
778 "test");
779
780 const struct {
781 int32_t transport_rtt_msec;
782 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type;
783 } tests[] = {
784 {5000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE},
785 {4000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE},
786 {3000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G},
787 {2000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G},
788 {1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G},
789 {1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G},
790 {700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G},
791 {500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G},
792 {400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G},
793 {300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G},
794 {200, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND},
795 {100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND},
796 {20, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND},
797 };
798
799 for (const auto& test : tests) {
800 estimator.set_transport_rtt(
801 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
802 estimator.set_recent_transport_rtt(
803 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
804 estimator.set_downlink_throughput_kbps(INT32_MAX);
805 estimator.set_recent_downlink_throughput_kbps(INT32_MAX);
806 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
807 }
808 }
809
810 // Tests that |GetEffectiveConnectionType| returns correct connection type when
811 // both HTTP RTT and throughput thresholds are specified in the variation
812 // params.
813 TEST(NetworkQualityEstimatorTest, ObtainThresholdsHttpRTTandThroughput) {
759 std::map<std::string, std::string> variation_params; 814 std::map<std::string, std::string> variation_params;
760 815
761 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000"; 816 variation_params["Offline.ThresholdMedianHttpRTTMsec"] = "4000";
762 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000"; 817 variation_params["Slow2G.ThresholdMedianHttpRTTMsec"] = "2000";
763 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000"; 818 variation_params["2G.ThresholdMedianHttpRTTMsec"] = "1000";
764 variation_params["3G.ThresholdMedianHttpRTTMsec"] = "500"; 819 variation_params["3G.ThresholdMedianHttpRTTMsec"] = "500";
765 variation_params["4G.ThresholdMedianHttpRTTMsec"] = "300"; 820 variation_params["4G.ThresholdMedianHttpRTTMsec"] = "300";
766 variation_params["Broadband.ThresholdMedianHttpRTTMsec"] = "100"; 821 variation_params["Broadband.ThresholdMedianHttpRTTMsec"] = "100";
767 822
768 variation_params["Offline.ThresholdMedianKbps"] = "10"; 823 variation_params["Offline.ThresholdMedianKbps"] = "10";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec)); 862 estimator.set_http_rtt(base::TimeDelta::FromMilliseconds(test.rtt_msec));
808 estimator.set_recent_http_rtt( 863 estimator.set_recent_http_rtt(
809 base::TimeDelta::FromMilliseconds(test.rtt_msec)); 864 base::TimeDelta::FromMilliseconds(test.rtt_msec));
810 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps); 865 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps);
811 estimator.set_recent_downlink_throughput_kbps( 866 estimator.set_recent_downlink_throughput_kbps(
812 test.downlink_throughput_kbps); 867 test.downlink_throughput_kbps);
813 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType()); 868 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
814 } 869 }
815 } 870 }
816 871
872 // Tests that |GetEffectiveConnectionType| returns correct connection type when
873 // both transport RTT and throughput thresholds are specified in the variation
874 // params.
875 TEST(NetworkQualityEstimatorTest, ObtainThresholdsTransportRTTandThroughput) {
876 std::map<std::string, std::string> variation_params;
877 variation_params["effective_connection_type_algorithm"] =
878 "TransportRTTOrDownstreamThroughput";
879
880 variation_params["Offline.ThresholdMedianTransportRTTMsec"] = "4000";
881 variation_params["Slow2G.ThresholdMedianTransportRTTMsec"] = "2000";
882 variation_params["2G.ThresholdMedianTransportRTTMsec"] = "1000";
883 variation_params["3G.ThresholdMedianTransportRTTMsec"] = "500";
884 variation_params["4G.ThresholdMedianTransportRTTMsec"] = "300";
885 variation_params["Broadband.ThresholdMedianTransportRTTMsec"] = "100";
886
887 variation_params["Offline.ThresholdMedianKbps"] = "10";
888 variation_params["Slow2G.ThresholdMedianKbps"] = "100";
889 variation_params["2G.ThresholdMedianKbps"] = "300";
890 variation_params["3G.ThresholdMedianKbps"] = "500";
891 variation_params["4G.ThresholdMedianKbps"] = "1000";
892 variation_params["Broadband.ThresholdMedianKbps"] = "2000";
893
894 TestNetworkQualityEstimator estimator(variation_params);
895
896 // Simulate the connection type as Wi-Fi so that GetEffectiveConnectionType
897 // does not return Offline if the device is offline.
898 estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI,
899 "test");
900
901 const struct {
902 int32_t transport_rtt_msec;
903 int32_t downlink_throughput_kbps;
904 NetworkQualityEstimator::EffectiveConnectionType expected_conn_type;
905 } tests[] = {
906 // Set RTT to a very low value to observe the effect of throughput.
907 // Throughput is the bottleneck.
908 {1, 5, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE},
909 {1, 10, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE},
910 {1, 50, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G},
911 {1, 100, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G},
912 {1, 150, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G},
913 {1, 300, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G},
914 {1, 400, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G},
915 {1, 500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G},
916 {1, 700, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G},
917 {1, 1000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_4G},
918 {1, 1500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND},
919 {1, 2500, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_BROADBAND},
920 // Set both RTT and throughput. RTT is the bottleneck.
921 {3000, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G},
922 {700, 25000, NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G},
923 };
924
925 for (const auto& test : tests) {
926 estimator.set_transport_rtt(
927 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
928 estimator.set_recent_transport_rtt(
929 base::TimeDelta::FromMilliseconds(test.transport_rtt_msec));
930 estimator.set_downlink_throughput_kbps(test.downlink_throughput_kbps);
931 estimator.set_recent_downlink_throughput_kbps(
932 test.downlink_throughput_kbps);
933 EXPECT_EQ(test.expected_conn_type, estimator.GetEffectiveConnectionType());
934 }
935 }
936
817 // Tests if |weight_multiplier_per_second_| is set to correct value for various 937 // Tests if |weight_multiplier_per_second_| is set to correct value for various
818 // values of half life parameter. 938 // values of half life parameter.
819 TEST(NetworkQualityEstimatorTest, HalfLifeParam) { 939 TEST(NetworkQualityEstimatorTest, HalfLifeParam) {
820 std::map<std::string, std::string> variation_params; 940 std::map<std::string, std::string> variation_params;
821 941
822 const struct { 942 const struct {
823 std::string description; 943 std::string description;
824 std::string variation_params_value; 944 std::string variation_params_value;
825 double expected_weight_multiplier; 945 double expected_weight_multiplier;
826 } tests[] = { 946 } tests[] = {
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( 1926 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType(
1807 effective_connection_type)); 1927 effective_connection_type));
1808 EXPECT_FALSE(connection_type_name.empty()); 1928 EXPECT_FALSE(connection_type_name.empty());
1809 EXPECT_EQ(effective_connection_type, 1929 EXPECT_EQ(effective_connection_type,
1810 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( 1930 NetworkQualityEstimator::GetEffectiveConnectionTypeForName(
1811 connection_type_name)); 1931 connection_type_name));
1812 } 1932 }
1813 } 1933 }
1814 1934
1815 } // namespace net 1935 } // namespace net
OLDNEW
« net/nqe/network_quality_estimator.cc ('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