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
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user