Skip to content
Snippets Groups Projects
Commit 0788d8ee authored by Paul Hu's avatar Paul Hu
Browse files

Add Thread#join to guarantee the termination of the thread

Also add MonitorThreadLeak annotation to check thread leak.

Test: atest ConnectivityCoverageTests --test-filter mdns*
Change-Id: Ie47f30360e36784428173f6cc87a4a6b09826405
parent 27662f0c
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,7 @@ import java.util.List; ...@@ -56,6 +56,7 @@ import java.util.List;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
/** Tests for {@link MdnsDiscoveryManager}. */ /** Tests for {@link MdnsDiscoveryManager}. */
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner.class) @RunWith(DevSdkIgnoreRunner.class)
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2) @DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
public class MdnsDiscoveryManagerTests { public class MdnsDiscoveryManagerTests {
...@@ -134,9 +135,10 @@ public class MdnsDiscoveryManagerTests { ...@@ -134,9 +135,10 @@ public class MdnsDiscoveryManagerTests {
} }
@After @After
public void tearDown() { public void tearDown() throws Exception {
if (thread != null) { if (thread != null) {
thread.quitSafely(); thread.quitSafely();
thread.join();
} }
} }
......
...@@ -49,6 +49,7 @@ private const val NO_CALLBACK_TIMEOUT_MS = 200L ...@@ -49,6 +49,7 @@ private const val NO_CALLBACK_TIMEOUT_MS = 200L
private const val TEST_ELAPSED_REALTIME_MS = 123L private const val TEST_ELAPSED_REALTIME_MS = 123L
private const val DEFAULT_TTL_TIME_MS = 120000L private const val DEFAULT_TTL_TIME_MS = 120000L
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner::class) @RunWith(DevSdkIgnoreRunner::class)
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2) @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2)
class MdnsServiceCacheTest { class MdnsServiceCacheTest {
...@@ -104,6 +105,7 @@ class MdnsServiceCacheTest { ...@@ -104,6 +105,7 @@ class MdnsServiceCacheTest {
@After @After
fun tearDown() { fun tearDown() {
thread.quitSafely() thread.quitSafely()
thread.join()
} }
private fun makeFlags(isExpiredServicesRemovalEnabled: Boolean = false) = private fun makeFlags(isExpiredServicesRemovalEnabled: Boolean = false) =
......
...@@ -87,6 +87,7 @@ import java.util.concurrent.TimeUnit; ...@@ -87,6 +87,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Stream; import java.util.stream.Stream;
/** Tests for {@link MdnsServiceTypeClient}. */ /** Tests for {@link MdnsServiceTypeClient}. */
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner.class) @RunWith(DevSdkIgnoreRunner.class)
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2) @DevSdkIgnoreRule.IgnoreUpTo(SC_V2)
public class MdnsServiceTypeClientTests { public class MdnsServiceTypeClientTests {
...@@ -230,9 +231,10 @@ public class MdnsServiceTypeClientTests { ...@@ -230,9 +231,10 @@ public class MdnsServiceTypeClientTests {
} }
@After @After
public void tearDown() { public void tearDown() throws Exception {
if (thread != null) { if (thread != null) {
thread.quitSafely(); thread.quitSafely();
thread.join();
} }
} }
......
...@@ -27,6 +27,7 @@ import org.mockito.Mockito.verify ...@@ -27,6 +27,7 @@ import org.mockito.Mockito.verify
private val LINKADDRV4 = LinkAddress("192.0.2.0/24") private val LINKADDRV4 = LinkAddress("192.0.2.0/24")
private val IFACE_IDX = 32 private val IFACE_IDX = 32
@DevSdkIgnoreRunner.MonitorThreadLeak
@RunWith(DevSdkIgnoreRunner::class) @RunWith(DevSdkIgnoreRunner::class)
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2) @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2)
internal class SocketNetlinkMonitorTest { internal class SocketNetlinkMonitorTest {
...@@ -43,6 +44,7 @@ internal class SocketNetlinkMonitorTest { ...@@ -43,6 +44,7 @@ internal class SocketNetlinkMonitorTest {
@After @After
fun tearDown() { fun tearDown() {
thread.quitSafely() thread.quitSafely()
thread.join()
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment