Merge "Add Thread#join to guarantee the termination of the thread" into main

This commit is contained in:
Paul Hu 2023-11-22 06:22:23 +00:00 • committed by Gerrit Code Review
commit 976e52a2c4
4 changed files with 10 additions and 2 deletions

View file

@ -56,6 +56,7 @@ import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
/** Tests for {@link MdnsDiscoveryManager}. */
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner.class)
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
public class MdnsDiscoveryManagerTests {
@ -134,9 +135,10 @@ public class MdnsDiscoveryManagerTests {
}
@After
public void tearDown() {
public void tearDown() throws Exception {
if (thread != null) {
thread.quitSafely();
thread.join();
}
}

View file

@ -49,6 +49,7 @@ private const val NO_CALLBACK_TIMEOUT_MS = 200L
private const val TEST_ELAPSED_REALTIME_MS = 123L
private const val DEFAULT_TTL_TIME_MS = 120000L
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner::class)
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2)
class MdnsServiceCacheTest {
@ -104,6 +105,7 @@ class MdnsServiceCacheTest {
@After
fun tearDown() {
thread.quitSafely()
thread.join()
}
private fun makeFlags(isExpiredServicesRemovalEnabled: Boolean = false) =

View file

@ -87,6 +87,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
/** Tests for {@link MdnsServiceTypeClient}. */
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner.class)
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
public class MdnsServiceTypeClientTests {
@ -230,9 +231,10 @@ public class MdnsServiceTypeClientTests {
}
@After
public void tearDown() {
public void tearDown() throws Exception {
if (thread != null) {
thread.quitSafely();
thread.join();
}
}

View file

@ -27,6 +27,7 @@ import org.mockito.Mockito.verify
private val LINKADDRV4 = LinkAddress("192.0.2.0/24")
private val IFACE_IDX = 32
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner::class)
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2)
internal class SocketNetlinkMonitorTest {
@ -43,6 +44,7 @@ internal class SocketNetlinkMonitorTest {
@After
fun tearDown() {
thread.quitSafely()
thread.join()
}
@Test