diff options
| author | 2022-11-21 11:45:37 -0800 | |
|---|---|---|
| committer | 2022-11-21 11:52:49 -0800 | |
| commit | d02d2edb77ec636a9b98cac2af762d97c864260a (patch) | |
| tree | 1bfa6fba66a004298000ef7781152cd7d15264d6 | |
| parent | ad227d66aa914c58da1387212987df844e7c7b98 (diff) | |
Changed UserVisibilityMediatorTestCase to use the main handler.
This test was creating a new handler thread as the goal is to make
sure the listener is called in the proper handler, but using the
test's main handler is enough (not to mention that sometimes the
new handler thread fails to start, which seems to be a test setup
issue).
Also decreased waiting time for no-events callbacks - given that
these are unit tests, it's ok to be aggressive and keep them small.
Bug: 259906148
Test: time atest --rerun-until-failure 100 FrameworksMockingServicesTests:com.android.server.pm.UserVisibilityMediatorSUSDTest FrameworksMockingServicesTests:com.android.server.pm.UserVisibilityMediatorMUMDTest
Change-Id: I0a144d60d12c623da7036501071a767e5a152af9
2 files changed, 10 insertions, 24 deletions
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/AsyncUserVisibilityListener.java b/services/tests/mockingservicestests/src/com/android/server/pm/AsyncUserVisibilityListener.java index 1a4a7bd4ff72..afcedd6f41bf 100644 --- a/services/tests/mockingservicestests/src/com/android/server/pm/AsyncUserVisibilityListener.java +++ b/services/tests/mockingservicestests/src/com/android/server/pm/AsyncUserVisibilityListener.java @@ -40,7 +40,8 @@ public final class AsyncUserVisibilityListener implements UserVisibilityListener private static final String TAG = AsyncUserVisibilityListener.class.getSimpleName(); private static final long WAIT_TIMEOUT_MS = 2_000; - private static final long WAIT_NO_EVENTS_TIMEOUT_MS = 1_000; + + private static final long WAIT_NO_EVENTS_TIMEOUT_MS = 100; private static int sNextId; diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java index 17ee90927977..6ceb38adf875 100644 --- a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java +++ b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java @@ -36,16 +36,14 @@ import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.assertThrows; import android.annotation.UserIdInt; -import android.os.HandlerThread; +import android.os.Handler; import android.util.IntArray; import android.util.Log; import com.android.internal.util.Preconditions; import com.android.server.ExtendedMockitoTestCase; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import java.util.Arrays; @@ -103,10 +101,8 @@ abstract class UserVisibilityMediatorTestCase extends ExtendedMockitoTestCase { protected static final boolean FG = true; protected static final boolean BG = false; - private static final HandlerThread sHandlerThread = new HandlerThread(TAG); - - protected final AsyncUserVisibilityListener.Factory mListenerFactory = - new AsyncUserVisibilityListener.Factory(mExpect, sHandlerThread); + private Handler mHandler; + protected AsyncUserVisibilityListener.Factory mListenerFactory; private final boolean mUsersOnSecondaryDisplaysEnabled; @@ -116,24 +112,13 @@ abstract class UserVisibilityMediatorTestCase extends ExtendedMockitoTestCase { mUsersOnSecondaryDisplaysEnabled = usersOnSecondaryDisplaysEnabled; } - @BeforeClass - public static final void startHandlerThread() { - Log.d(TAG, "Starting handler thread " + sHandlerThread); - sHandlerThread.start(); - } - - @AfterClass - public static final void quitHandlerThread() { - Log.d(TAG, "Quitting handler thread " + sHandlerThread); - if (!sHandlerThread.quit()) { - Log.w(TAG, "sHandlerThread(" + sHandlerThread + ").quit() returned false"); - } - } - @Before public final void setFixtures() { - mMediator = new UserVisibilityMediator(mUsersOnSecondaryDisplaysEnabled, - sHandlerThread.getThreadHandler()); + mHandler = Handler.getMain(); + Thread thread = mHandler.getLooper().getThread(); + Log.i(TAG, "setFixtures(): using thread " + thread + " (from handler " + mHandler + ")"); + mListenerFactory = new AsyncUserVisibilityListener.Factory(mExpect, thread); + mMediator = new UserVisibilityMediator(mUsersOnSecondaryDisplaysEnabled, mHandler); mDumpableDumperRule.addDumpable(mMediator); } |