Request cell in #testExplicitlySelected

When the test is very slow (e.g. in coverage tests) it's
possible this test takes > 30 seconds and cell finishes
lingering before the end of the test. This will cause a
disconnection of cell before wifi and fail the test.

Address this by requesting cell.

Bug: 273383734
Test: atest --iterations 100 'FrameworksNetTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testExplicitlySelected'
Change-Id: I06a7ef82de966b522e58a969c25a4c0335dbc497
This commit is contained in:
Chalard Jean
2023-03-16 18:23:32 +09:00
parent 4bc39e2d22
commit 7cf34ec1cd

View File

@@ -3815,13 +3815,13 @@ public class ConnectivityServiceTest {
@Test @Test
public void testExplicitlySelected() throws Exception { public void testExplicitlySelected() throws Exception {
NetworkRequest request = new NetworkRequest.Builder() final NetworkRequest request = new NetworkRequest.Builder()
.clearCapabilities().addCapability(NET_CAPABILITY_INTERNET) .clearCapabilities().addCapability(NET_CAPABILITY_INTERNET)
.build(); .build();
TestNetworkCallback callback = new TestNetworkCallback(); final TestNetworkCallback callback = new TestNetworkCallback();
mCm.registerNetworkCallback(request, callback); mCm.registerNetworkCallback(request, callback);
// Bring up validated cell. // Bring up validated cell
mCellAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR); mCellAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
mCellAgent.connect(true); mCellAgent.connect(true);
callback.expectAvailableThenValidatedCallbacks(mCellAgent); callback.expectAvailableThenValidatedCallbacks(mCellAgent);
@@ -3879,6 +3879,12 @@ public class ConnectivityServiceTest {
assertEquals(mWiFiAgent.getNetwork(), mCm.getActiveNetwork()); assertEquals(mWiFiAgent.getNetwork(), mCm.getActiveNetwork());
expectUnvalidationCheckWillNotNotify(mWiFiAgent); expectUnvalidationCheckWillNotNotify(mWiFiAgent);
// Now request cell so it doesn't disconnect during the test
final NetworkRequest cellRequest = new NetworkRequest.Builder()
.clearCapabilities().addTransportType(TRANSPORT_CELLULAR).build();
final TestNetworkCallback cellCallback = new TestNetworkCallback();
mCm.requestNetwork(cellRequest, cellCallback);
mEthernetAgent = new TestNetworkAgentWrapper(TRANSPORT_ETHERNET); mEthernetAgent = new TestNetworkAgentWrapper(TRANSPORT_ETHERNET);
mEthernetAgent.connect(true); mEthernetAgent.connect(true);
callback.expectAvailableCallbacksUnvalidated(mEthernetAgent); callback.expectAvailableCallbacksUnvalidated(mEthernetAgent);
@@ -3920,6 +3926,7 @@ public class ConnectivityServiceTest {
callback.expect(LOST, mWiFiAgent); callback.expect(LOST, mWiFiAgent);
callback.expect(LOST, mCellAgent); callback.expect(LOST, mCellAgent);
mCm.unregisterNetworkCallback(cellCallback);
} }
private void doTestFirstEvaluation( private void doTestFirstEvaluation(