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

Stop the created handler threads on the tests

The created handler thread will stay there for a while until
all the tests are finished. This is considered as a leakage
which will take the resource from the devices. In low end
devices, this may possibly impact the performance. The created
threads should be closed explicitly.

Test: atest ConnectivityCoverageTests ConntrackSocketTest
Change-Id: Ic1beb2a210e7c8c80c66fc9e0727c47599150672
parent f24beefe
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,7 @@ import com.android.net.module.util.netlink.NetlinkMessage;
import com.android.net.module.util.netlink.NetlinkUtils;
import com.android.net.module.util.netlink.StructNlMsgHdr;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -84,6 +85,14 @@ public class ConntrackSocketTest {
mOffloadHw = new OffloadHardwareInterface(mHandler, mLog, mDeps);
}
@After
public void tearDown() throws Exception {
if (mHandlerThread != null) {
mHandlerThread.quitSafely();
mHandlerThread.join();
}
}
void findConnectionOrThrow(FileDescriptor fd, InetSocketAddress local, InetSocketAddress remote)
throws Exception {
Log.d(TAG, "Looking for socket " + local + " -> " + remote);
......
......@@ -42,6 +42,7 @@ import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRunner;
import com.android.testutils.HandlerUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -69,6 +70,7 @@ public class MdnsMultinetworkSocketClientTest {
@Mock private SocketCreationCallback mSocketCreationCallback;
@Mock private SharedLog mSharedLog;
private MdnsMultinetworkSocketClient mSocketClient;
private HandlerThread mHandlerThread;
private Handler mHandler;
private SocketKey mSocketKey;
......@@ -76,14 +78,23 @@ public class MdnsMultinetworkSocketClientTest {
public void setUp() throws SocketException {
MockitoAnnotations.initMocks(this);
final HandlerThread thread = new HandlerThread("MdnsMultinetworkSocketClientTest");
thread.start();
mHandler = new Handler(thread.getLooper());
mHandlerThread = new HandlerThread("MdnsMultinetworkSocketClientTest");
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper());
mSocketKey = new SocketKey(1000 /* interfaceIndex */);
mSocketClient = new MdnsMultinetworkSocketClient(thread.getLooper(), mProvider, mSharedLog);
mSocketClient = new MdnsMultinetworkSocketClient(
mHandlerThread.getLooper(), mProvider, mSharedLog);
mHandler.post(() -> mSocketClient.setCallback(mCallback));
}
@After
public void tearDown() throws Exception {
if (mHandlerThread != null) {
mHandlerThread.quitSafely();
mHandlerThread.join();
}
}
private SocketCallback expectSocketCallback() {
return expectSocketCallback(mListener, mNetwork);
}
......
......@@ -59,6 +59,7 @@ import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRunner;
import com.android.testutils.HandlerUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -139,6 +140,14 @@ public class NetworkStatsObserversTest {
mUsageCallback = new TestableUsageCallback(mUsageCallbackBinder);
}
@After
public void tearDown() throws Exception {
if (mObserverHandlerThread != null) {
mObserverHandlerThread.quitSafely();
mObserverHandlerThread.join();
}
}
@Test
public void testRegister_thresholdTooLow_setsDefaultThreshold() throws Exception {
final long thresholdTooLowBytes = 1L;
......
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