Commit 10d1fd5f authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Force recompute ECT when overriding the RTT values in NQE test class

When RTT values are overridden in the network quality estimator test
class, then the effective connection type is immediately recomputed.
This makes it simpler to write tests. Without this change, the caller
has to create and run a main frame URL request (which also
forces recomputation of ECT).

Bug: 704339
Change-Id: I4f92038a5577991a87d561ac4f4b2bcdd8172d79
TBR: mmenke@chromium.org,mpearson@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/874872
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#530314}
parent b4ff0419
......@@ -87,8 +87,7 @@ TEST_F(NetworkMetricsProviderTest, EffectiveConnectionType) {
// Set RTT so that the effective connection type is computed as 2G.
estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(1500));
estimator.set_start_time_null_http_rtt(
base::TimeDelta::FromMilliseconds(1500));
estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(1500));
EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
network_metrics_provider.effective_connection_type_);
EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
......@@ -112,8 +111,7 @@ TEST_F(NetworkMetricsProviderTest, EffectiveConnectionType) {
// Set RTT so that the effective connection type is computed as SLOW_2G.
estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(3000));
estimator.set_start_time_null_http_rtt(
base::TimeDelta::FromMilliseconds(3000));
estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(3000));
// Running a request would cause the effective connection type to be computed
// as SLOW_2G, and observers to be notified.
estimator.RunOneRequest();
......@@ -160,8 +158,7 @@ TEST_F(NetworkMetricsProviderTest, ECTAmbiguousOnConnectionTypeChange) {
// Set RTT so that the effective connection type is computed as 2G.
estimator.set_recent_http_rtt(base::TimeDelta::FromMilliseconds(1500));
estimator.set_start_time_null_http_rtt(
base::TimeDelta::FromMilliseconds(1500));
estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(1500));
// Running a request would cause the effective connection type to be computed
// as 2G, and observers to be notified.
estimator.RunOneRequest();
......
......@@ -19,39 +19,24 @@ TEST(NetworkQualityObserverImplTest, TestObserverNotified) {
base::MessageLoopForIO message_loop;
net::TestNetworkQualityEstimator estimator;
estimator.set_start_time_null_http_rtt(base::TimeDelta::FromMilliseconds(1));
estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(1));
NetworkQualityObserverImpl observer(&estimator);
// Give a chance for |observer| to register with the |estimator|.
base::RunLoop().RunUntilIdle();
// Run one main frame request to force recomputation of effective connection
// type.
estimator.RunOneRequest();
base::RunLoop().RunUntilIdle();
base::HistogramTester histogram_tester;
estimator.set_start_time_null_http_rtt(
base::TimeDelta::FromMilliseconds(500));
// Run one main frame request to force recomputation of effective connection
// type.
estimator.RunOneRequest();
base::RunLoop().RunUntilIdle();
estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(500));
// RTT changed from 1 msec to 500 msec.
histogram_tester.ExpectBucketCount(
"NQE.ContentObserver.NetworkQualityMeaningfullyChanged", 1, 1);
estimator.set_start_time_null_http_rtt(
base::TimeDelta::FromMilliseconds(625));
estimator.RunOneRequest();
base::RunLoop().RunUntilIdle();
estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(625));
// RTT changed from 500 msec to 625 msec.
histogram_tester.ExpectBucketCount(
"NQE.ContentObserver.NetworkQualityMeaningfullyChanged", 1, 2);
estimator.set_start_time_null_http_rtt(
base::TimeDelta::FromMilliseconds(626));
estimator.RunOneRequest();
base::RunLoop().RunUntilIdle();
estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(626));
// RTT changed from 625 msec to 626 msec which is not a meaningful change.
histogram_tester.ExpectBucketCount(
"NQE.ContentObserver.NetworkQualityMeaningfullyChanged", 1, 2);
......
......@@ -768,22 +768,22 @@ TEST_P(HttpProxyClientSocketPoolTest, ProxyPoolTimeoutWithExperiment) {
// Timeout should be |transport_rtt_multiplier| times the transport RTT
// estimate.
base::TimeDelta rtt_estimate = base::TimeDelta::FromSeconds(7);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(rtt_estimate + rtt_estimate, pool_->ConnectionTimeout());
// A change in RTT estimate should also change the connection timeout.
rtt_estimate = base::TimeDelta::FromSeconds(8);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(rtt_estimate + rtt_estimate, pool_->ConnectionTimeout());
// Connection timeout should not exceed |max_timeout|.
rtt_estimate = base::TimeDelta::FromSeconds(25);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(max_timeout, pool_->ConnectionTimeout());
// Connection timeout should not be less than |min_timeout|.
rtt_estimate = base::TimeDelta::FromSeconds(0);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(min_timeout, pool_->ConnectionTimeout());
}
......@@ -802,24 +802,24 @@ TEST_P(HttpProxyClientSocketPoolTest,
// Timeout should be |transport_rtt_multiplier| times the transport RTT
// estimate.
base::TimeDelta rtt_estimate = base::TimeDelta::FromSeconds(2);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(rtt_estimate + rtt_estimate + rtt_estimate,
pool_->ConnectionTimeout());
// A change in RTT estimate should also change the connection timeout.
rtt_estimate = base::TimeDelta::FromSeconds(7);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(rtt_estimate + rtt_estimate + rtt_estimate,
pool_->ConnectionTimeout());
// Connection timeout should not exceed |max_timeout|.
rtt_estimate = base::TimeDelta::FromSeconds(35);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(max_timeout, pool_->ConnectionTimeout());
// Connection timeout should not be less than |min_timeout|.
rtt_estimate = base::TimeDelta::FromSeconds(0);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_EQ(min_timeout, pool_->ConnectionTimeout());
}
......@@ -834,24 +834,24 @@ TEST_P(HttpProxyClientSocketPoolTest,
// Timeout should be |transport_rtt_multiplier| times the transport RTT
// estimate.
base::TimeDelta rtt_estimate = base::TimeDelta::FromMilliseconds(10);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
// Connection timeout should not be less than the transport RTT estimate.
EXPECT_LE(rtt_estimate, pool_->ConnectionTimeout());
// A change in RTT estimate should also change the connection timeout.
rtt_estimate = base::TimeDelta::FromSeconds(10);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
// Connection timeout should not be less than the transport RTT estimate.
EXPECT_LE(rtt_estimate, pool_->ConnectionTimeout());
// Set RTT to a very large value.
rtt_estimate = base::TimeDelta::FromMinutes(60);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_GT(rtt_estimate, pool_->ConnectionTimeout());
// Set RTT to a very small value.
rtt_estimate = base::TimeDelta::FromSeconds(0);
estimator()->set_start_time_null_transport_rtt(rtt_estimate);
estimator()->SetStartTimeNullTransportRtt(rtt_estimate);
EXPECT_LT(rtt_estimate, pool_->ConnectionTimeout());
}
......
......@@ -359,6 +359,10 @@ class NET_EXPORT NetworkQualityEstimator
// the signal quality.
virtual int32_t GetCurrentSignalStrength() const;
// Forces computation of effective connection type, and notifies observers
// if there is a change in its value.
void ComputeEffectiveConnectionType();
// Observer list for RTT or throughput estimates. Protected for testing.
base::ObserverList<RTTAndThroughputEstimatesObserver>
rtt_and_throughput_estimates_observer_list_;
......@@ -530,10 +534,6 @@ class NET_EXPORT NetworkQualityEstimator
// Periodically updates |increase_in_transport_rtt_| by posting delayed tasks.
void IncreaseInTransportRTTUpdater();
// Forces computation of effective connection type, and notifies observers
// if there is a change in its value.
void ComputeEffectiveConnectionType();
const char* GetNameForStatistic(int i) const;
// Gathers metrics for the next connection type. Called when there is a change
......
......@@ -361,4 +361,24 @@ void TestNetworkQualityEstimator::
observer);
}
void TestNetworkQualityEstimator::SetStartTimeNullHttpRtt(
const base::TimeDelta http_rtt) {
start_time_null_http_rtt_ = http_rtt;
// Force compute effective connection type so that the new RTT value is
// immediately picked up. This ensures that the next call to
// GetEffectiveConnectionType() returns the effective connnection type
// that was computed based on |http_rtt|.
ComputeEffectiveConnectionType();
}
void TestNetworkQualityEstimator::SetStartTimeNullTransportRtt(
const base::TimeDelta transport_rtt) {
start_time_null_transport_rtt_ = transport_rtt;
// Force compute effective connection type so that the new RTT value is
// immediately picked up. This ensures that the next call to
// GetEffectiveConnectionType() returns the effective connnection type
// that was computed based on |transport_rtt|.
ComputeEffectiveConnectionType();
}
} // namespace net
......@@ -122,9 +122,8 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator {
void NotifyRTTAndThroughputEstimatesObserverIfPresent(
RTTAndThroughputEstimatesObserver* observer) const override;
void set_start_time_null_http_rtt(const base::TimeDelta& http_rtt) {
start_time_null_http_rtt_ = http_rtt;
}
// Force set the HTTP RTT estimate.
void SetStartTimeNullHttpRtt(const base::TimeDelta http_rtt);
void set_recent_http_rtt(const base::TimeDelta& recent_http_rtt) {
// Callers should not set effective connection type along with the
......@@ -138,9 +137,8 @@ class TestNetworkQualityEstimator : public NetworkQualityEstimator {
bool GetRecentHttpRTT(const base::TimeTicks& start_time,
base::TimeDelta* rtt) const override;
void set_start_time_null_transport_rtt(const base::TimeDelta& transport_rtt) {
start_time_null_transport_rtt_ = transport_rtt;
}
// Force set the transport RTT estimate.
void SetStartTimeNullTransportRtt(const base::TimeDelta transport_rtt);
void set_recent_transport_rtt(const base::TimeDelta& recent_transport_rtt) {
// Callers should not set effective connection type along with the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment