Fix flaky ActivityManagerServiceTest.
Ignore the runnable posted by the UidObserverController as the test doesn't need it and might result in unintended data access from the handler thread. Bug: 205035410 Test: atest ./services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java Change-Id: I65da69508f055f23692ff73bd436db399b2ee607
This commit is contained in:
@@ -129,6 +129,10 @@ public class UidObserverController {
|
||||
return mValidateUids;
|
||||
}
|
||||
|
||||
Runnable getDispatchRunnableForTest() {
|
||||
return mDispatchRunnable;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static int mergeWithPendingChange(int currentChange, int pendingChange) {
|
||||
// If there is no change in idle or active state, then keep whatever was pending.
|
||||
|
||||
@@ -98,6 +98,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
@@ -164,6 +165,8 @@ public class ActivityManagerServiceTest {
|
||||
mAms.mWaitForNetworkTimeoutMs = 2000;
|
||||
mAms.mActivityTaskManager = new ActivityTaskManagerService(mContext);
|
||||
mAms.mActivityTaskManager.initialize(null, null, mHandler.getLooper());
|
||||
mHandler.setRunnablesToIgnore(
|
||||
List.of(mAms.mUidObserverController.getDispatchRunnableForTest()));
|
||||
}
|
||||
|
||||
private void mockNoteOperation() {
|
||||
@@ -983,12 +986,21 @@ public class ActivityManagerServiceTest {
|
||||
private static final long WAIT_FOR_MSG_TIMEOUT_MS = 4000; // 4 sec
|
||||
private static final long WAIT_FOR_MSG_INTERVAL_MS = 400; // 0.4 sec
|
||||
|
||||
private Set<Integer> mMsgsHandled = new HashSet<>();
|
||||
private final Set<Integer> mMsgsHandled = new HashSet<>();
|
||||
private final List<Runnable> mRunnablesToIgnore = new ArrayList<>();
|
||||
|
||||
TestHandler(Looper looper) {
|
||||
super(looper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchMessage(Message msg) {
|
||||
if (msg.getCallback() != null && mRunnablesToIgnore.contains(msg.getCallback())) {
|
||||
return;
|
||||
}
|
||||
super.dispatchMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mMsgsHandled.add(msg.what);
|
||||
@@ -1004,6 +1016,11 @@ public class ActivityManagerServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void setRunnablesToIgnore(List<Runnable> runnables) {
|
||||
mRunnablesToIgnore.clear();
|
||||
mRunnablesToIgnore.addAll(runnables);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
mMsgsHandled.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user