From 8d336eb1a3d83c8d7d334a15d4ef8d4aec693c80 Mon Sep 17 00:00:00 2001 From: chiachangwang Date: Thu, 17 Aug 2023 05:48:55 +0000 Subject: [PATCH] Stop the created handler threads 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 FrameworksNetTests Change-Id: I332d55d8effdb975fd9a8953b19910a7fb25e426 --- .../connectivity/AutomaticOnOffKeepaliveTrackerTest.java | 4 ++++ .../server/connectivity/KeepaliveStatsTrackerTest.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java b/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java index b69b042667..628958789a 100644 --- a/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java +++ b/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java @@ -368,6 +368,10 @@ public class AutomaticOnOffKeepaliveTrackerTest { @After public void teardown() throws Exception { TestKeepaliveInfo.closeAllSockets(); + if (mHandlerThread != null) { + mHandlerThread.quitSafely(); + mHandlerThread.join(); + } } private final class AOOTestHandler extends Handler { diff --git a/tests/unit/java/com/android/server/connectivity/KeepaliveStatsTrackerTest.java b/tests/unit/java/com/android/server/connectivity/KeepaliveStatsTrackerTest.java index fa703eb93a..90a0eddc0a 100644 --- a/tests/unit/java/com/android/server/connectivity/KeepaliveStatsTrackerTest.java +++ b/tests/unit/java/com/android/server/connectivity/KeepaliveStatsTrackerTest.java @@ -67,6 +67,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.Rule; import org.junit.Test; @@ -240,6 +241,14 @@ public class KeepaliveStatsTrackerTest { HandlerUtils.waitForIdle(mTestHandler, TIMEOUT_MS); } + @After + public void tearDown() throws Exception { + if (mHandlerThread != null) { + mHandlerThread.quitSafely(); + mHandlerThread.join(); + } + } + private void setElapsedRealtime(long time) { doReturn(time).when(mDependencies).getElapsedRealtime(); }