Connectivity Tests: join handler thread after calling quitSafely

Somewhat surprisingly, HandlerThread#quitSafely is *not* a synchronous
method, so the tearDown() method still needs to wait for the thread to
join.

Test: TH
Change-Id: I0433e2100adf9299a67af5c259a518cf44f4be57
This commit is contained in:
Patrick Rohr
2023-03-14 14:42:07 -07:00
parent a08f8867f8
commit 98021b650b
15 changed files with 21 additions and 3 deletions

View File

@@ -156,6 +156,7 @@ class TetheringNotificationUpdaterTest {
@After
fun tearDown() {
fakeTetheringThread.quitSafely()
fakeTetheringThread.join()
}
private fun verifyActivityPendingIntent(intent: Intent, flags: Int) {

View File

@@ -79,6 +79,7 @@ class NetworkProviderTest {
@After
fun tearDown() {
mHandlerThread.quitSafely()
mHandlerThread.join()
instrumentation.getUiAutomation().dropShellPermissionIdentity()
}

View File

@@ -191,6 +191,7 @@ class NetworkAgentTest {
callbacksToCleanUp.forEach { mCM.unregisterNetworkCallback(it) }
qosTestSocket?.close()
mHandlerThread.quitSafely()
mHandlerThread.join()
instrumentation.getUiAutomation().dropShellPermissionIdentity()
}

View File

@@ -90,6 +90,7 @@ class NetworkScoreTest {
mCm.unregisterNetworkCallback(agentCleanUpCb)
mHandlerThread.quitSafely()
mHandlerThread.join()
callbacksToCleanUp.forEach { mCm.unregisterNetworkCallback(it) }
}

View File

@@ -146,6 +146,7 @@ class NetworkValidationTest {
httpServer.stop()
handlerThread.threadHandler.post { reader.stop() }
handlerThread.quitSafely()
handlerThread.join()
iface.fileDescriptor.close()
}

View File

@@ -432,6 +432,7 @@ class NsdManagerTest {
}
handlerThread.waitForIdle(TIMEOUT_MS)
handlerThread.quitSafely()
handlerThread.join()
}
@Test

View File

@@ -2219,7 +2219,9 @@ public class ConnectivityServiceTest {
ConnectivityResources.setResourcesContextForTest(null);
mCsHandlerThread.quitSafely();
mCsHandlerThread.join();
mAlarmManagerThread.quitSafely();
mAlarmManagerThread.join();
}
private void mockDefaultPackages() throws Exception {
@@ -10126,6 +10128,7 @@ public class ConnectivityServiceTest {
b2.expectBroadcast();
VMSHandlerThread.quitSafely();
VMSHandlerThread.join();
}
@Test @IgnoreUpTo(Build.VERSION_CODES.S_V2)
@@ -16974,6 +16977,7 @@ public class ConnectivityServiceTest {
} finally {
cellFactory.terminate();
handlerThread.quitSafely();
handlerThread.join();
}
}

View File

@@ -97,6 +97,7 @@ class MdnsAdvertiserTest {
@After
fun tearDown() {
thread.quitSafely()
thread.join()
}
@Test

View File

@@ -63,6 +63,7 @@ class MdnsAnnouncerTest {
@After
fun tearDown() {
thread.quitSafely()
thread.join()
}
private class TestAnnouncementInfo(

View File

@@ -136,6 +136,7 @@ class MdnsInterfaceAdvertiserTest {
@After
fun tearDown() {
thread.quitSafely()
thread.join()
}
@Test

View File

@@ -68,6 +68,7 @@ class MdnsProberTest {
@After
fun tearDown() {
thread.quitSafely()
thread.join()
}
private class TestProbeInfo(probeRecords: List<MdnsRecord>, private val delayMs: Long = 1L) :

View File

@@ -79,6 +79,7 @@ class MdnsRecordRepositoryTest {
@After
fun tearDown() {
thread.quitSafely()
thread.join()
}
@Test

View File

@@ -86,8 +86,9 @@ public class EthernetTrackerTest {
}
@After
public void cleanUp() {
public void cleanUp() throws InterruptedException {
mHandlerThread.quitSafely();
mHandlerThread.join();
}
private void initMockResources() {

View File

@@ -36,7 +36,6 @@ import androidx.test.InstrumentationRegistry;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRunner;
import com.android.testutils.HandlerUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -139,6 +138,8 @@ public class IpConfigStoreTest {
}
@Override
public void quitHandlerThread(HandlerThread handlerThread) {
// Don't join in here, quitHandlerThread runs on the
// handler thread itself.
testHandlerThread.quitSafely();
}
};
@@ -155,7 +156,7 @@ public class IpConfigStoreTest {
final DelayedDiskWrite writer = new DelayedDiskWrite(dependencies);
final IpConfigStore store = new IpConfigStore(writer);
store.writeIpConfigurations(configFile.getPath(), expectedNetworks);
HandlerUtils.waitForIdle(testHandlerThread, TIMEOUT_MS);
testHandlerThread.join();
// Read IP config from the file path.
final ArrayMap<String, IpConfiguration> actualNetworks =

View File

@@ -539,6 +539,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
mService = null;
mHandlerThread.quitSafely();
mHandlerThread.join();
}
private void initWifiStats(NetworkStateSnapshot snapshot) throws Exception {