Commit 35e78f28 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

[reland] network: de-flake NetworkQualityEstimator throttling test

This test has is flaky when run on devices that have a real wifi or
cellular connection, because in that situation, the call to
SimulateNetworkChange() can cause an arbitrary number of real calls
to GetCurrentSignalStrengthWithThrottling(). This change de-flakes
the test in that situation by:

1) Delaying constructing the HistogramTester, to avoid counting
   those calls, and
2) Advancing the fake time the test uses at the start of the test,
   so that the NetworkQualityEstimator under test is never in its
   timeout period when the test starts

This change does not re-enable the test on Android yet, since it seems
to be still flaky there for unclear reasons.

Bug: 1133439,1130720
Change-Id: I152f43f9c66ccef29060c48201fb7b4e8868fafe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2476812Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#817719}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485194
Cr-Commit-Position: refs/heads/master@{#818533}
parent 1a347670
......@@ -3071,21 +3071,28 @@ TEST_F(NetworkQualityEstimatorTest, TestPeerToPeerConnectionsCountObserver) {
// Tests that the signal strength API is not called too frequently.
TEST_F(NetworkQualityEstimatorTest, MAYBE_CheckSignalStrength) {
base::HistogramTester histogram_tester;
constexpr char histogram_name[] = "NQE.SignalStrengthQueried.WiFi";
constexpr int kWiFiSignalStrengthQueryIntervalSeconds = 30 * 60;
std::map<std::string, std::string> variation_params;
variation_params["get_signal_strength_and_detailed_network_id"] = "true";
TestNetworkQualityEstimator estimator(variation_params);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test");
base::SimpleTestTickClock tick_clock;
tick_clock.SetNowTicks(base::TimeTicks::Now());
// SimulateNetworkChange() above can produce entries in the histogram bucket
// if the test system has real wifi or cellular connections, and can also
// leave the NQE inside its timeout. To avoid that, fastforward fake time for
// more than the query interval.
tick_clock.SetNowTicks(base::TimeTicks::Now() +
base::TimeDelta::FromSeconds(
kWiFiSignalStrengthQueryIntervalSeconds * 2));
estimator.SetTickClockForTesting(&tick_clock);
base::HistogramTester histogram_tester;
base::Optional<int32_t> signal_strength =
estimator.GetCurrentSignalStrengthWithThrottling();
......
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