Fix the test flake in testChangeUnderlyingNetworks
The testChangeUnderlyingNetworks test enables the Wi-Fi network
and ensures it's connected. However, the CS can switch the
default network to Wi-Fi at any time when it becomes validated,
and if this happens after the test obtains the active network,
it leads to a mismatch on underlying networks and causes the test
to fail. Therefore, ensure the Wi-Fi network is validated before
obtaining the active network.
Fix: 332967125
Test: atest CtsHostsideNetworkTests:com.android.cts.net.\
HostsideVpnTests#testChangeUnderlyingNetworks --iteration
Change-Id: If71c2ea6608f26b1dbc9802ef49e1f14b202c156
diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java
index 0f86d78..f5275bc 100755
--- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java
+++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java
@@ -124,6 +124,7 @@
import com.android.net.module.util.CollectionUtils;
import com.android.net.module.util.PacketBuilder;
import com.android.testutils.AutoReleaseNetworkCallbackRule;
+import com.android.testutils.ConnectUtil;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import com.android.testutils.RecorderCallback;
@@ -221,6 +222,7 @@
private WifiManager mWifiManager;
private RemoteSocketFactoryClient mRemoteSocketFactoryClient;
private CtsNetUtils mCtsNetUtils;
+ private ConnectUtil mConnectUtil;
private PackageManager mPackageManager;
private Context mTestContext;
private Context mTargetContext;
@@ -271,6 +273,7 @@
mRemoteSocketFactoryClient.bind();
mDevice.waitForIdle();
mCtsNetUtils = new CtsNetUtils(mTestContext);
+ mConnectUtil = new ConnectUtil(mTestContext);
mPackageManager = mTestContext.getPackageManager();
}
@@ -893,7 +896,7 @@
final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
testAndCleanup(() -> {
// Ensure both of wifi and mobile data are connected.
- final Network wifiNetwork = mCtsNetUtils.ensureWifiConnected();
+ final Network wifiNetwork = mConnectUtil.ensureWifiValidated();
final Network cellNetwork = mNetworkCallbackRule.requestCell();
// Store current default network.
final Network defaultNetwork = mCM.getActiveNetwork();