Improve error message when testing network factory

Currently, when network factory is under testing, but failed
without terminating the network factory. The mocked network
factory will stay registered and trigger another assertion
fail in teardown(). Thus, the test suite will only shows
the callstack that generated in teardown() instead of the
original fail. The error message is misleading and not useful
at all.

Thus, safely terminate and quit mocked network factory after
testing to prevent assertion fail in teardown().

Test: atest ConnectivityServiceTest#testMobileDataAlwaysOn
Bug: 175180558
Change-Id: I0f96332cc05221e576bd792c6cd26d9dccb4e228
This commit is contained in:
junyulai
2020-12-16 23:07:58 +08:00
parent 67f888738b
commit 0ce5cb98b4

View File

@@ -3622,6 +3622,8 @@ public class ConnectivityServiceTest {
// Register the factory and expect it to start looking for a network.
testFactory.expectAddRequestsWithScores(0); // Score 0 as the request is not served yet.
testFactory.register();
try {
testFactory.waitForNetworkRequests(1);
assertTrue(testFactory.getMyStartRequested());
@@ -3648,7 +3650,8 @@ public class ConnectivityServiceTest {
mCellNetworkAgent.connect(true);
cellNetworkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
testFactory.waitForNetworkRequests(2);
assertFalse(testFactory.getMyStartRequested()); // Because the cell network outscores us.
assertFalse(
testFactory.getMyStartRequested()); // Because the cell network outscores us.
// Check that cell data stays up.
waitForIdle();
@@ -3663,11 +3666,12 @@ public class ConnectivityServiceTest {
// ... and cell data to be torn down.
cellNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
assertLength(1, mCm.getAllNetworks());
} finally {
testFactory.terminate();
mCm.unregisterNetworkCallback(cellNetworkCallback);
handlerThread.quit();
}
}
@Test
public void testAvoidBadWifiSetting() throws Exception {