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
This commit is contained in:
Paul Hu 2024-04-22 06:49:47 +00:00
commit 1e7203bfd3

View file

@ -124,6 +124,7 @@ import com.android.net.module.util.ArrayTrackRecord;
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 @@ public class VpnTest {
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 @@ public class VpnTest {
mRemoteSocketFactoryClient.bind();
mDevice.waitForIdle();
mCtsNetUtils = new CtsNetUtils(mTestContext);
mConnectUtil = new ConnectUtil(mTestContext);
mPackageManager = mTestContext.getPackageManager();
}
@ -893,7 +896,7 @@ public class VpnTest {
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();