summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Riddle Hsu <riddlehsu@google.com> 2020-08-24 23:13:50 +0800
committer Riddle Hsu <riddlehsu@google.com> 2020-08-24 15:22:34 +0000
commitdadb3dc0fd9545c8f118a021e1bee70246b7f4fe (patch)
tree7af5c38d099a4461c46a92e7ff389ec6f175065c
parentd2e2eda8a23800b0043ca8b20619ac15e21defcc (diff)
Reduce flakiness of TaskStackChangedListenerTest
It is more stable to use count down latch to verify, instead of waiting for main thread idle. Also simplify testTaskStackChanged_afterFinish that it doesn't need to start 2 activities which may need to handle more races. Just verify the result after finishing the current one. Bug: 130388819 Bug: 154640614 Test: TaskStackChangedListenerTest#testTaskStackChanged_afterFinish TaskStackChangedListenerTest#testTaskStackChanged_resumeWhilePausing Change-Id: I7e88e7f1f470b04cad8a348932bb784bf8f3e5f0
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java56
1 files changed, 10 insertions, 46 deletions
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java b/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java
index bce1142c99be..ca3f815698e8 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java
@@ -53,7 +53,6 @@ import androidx.test.filters.FlakyTest;
import androidx.test.filters.MediumTest;
import com.android.compatibility.common.util.SystemUtil;
-import com.android.internal.annotations.GuardedBy;
import org.junit.After;
import org.junit.Before;
@@ -76,14 +75,10 @@ public class TaskStackChangedListenerTest {
private static final int WAIT_TIMEOUT_MS = 5000;
private static final Object sLock = new Object();
- @GuardedBy("sLock")
- private static boolean sTaskStackChangedCalled;
- private static boolean sActivityBResumed;
@Before
public void setUp() throws Exception {
mService = ActivityManager.getService();
- sTaskStackChangedCalled = false;
}
@After
@@ -94,47 +89,33 @@ public class TaskStackChangedListenerTest {
@Test
@Presubmit
- @FlakyTest(bugId = 130388819)
public void testTaskStackChanged_afterFinish() throws Exception {
+ final TestActivity activity = startTestActivity(ActivityA.class);
+ final CountDownLatch latch = new CountDownLatch(1);
registerTaskStackChangedListener(new TaskStackListener() {
@Override
public void onTaskStackChanged() throws RemoteException {
- synchronized (sLock) {
- sTaskStackChangedCalled = true;
- }
+ latch.countDown();
}
});
- Context context = getInstrumentation().getContext();
- context.startActivity(
- new Intent(context, ActivityA.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
- UiDevice.getInstance(getInstrumentation()).waitForIdle();
- synchronized (sLock) {
- assertTrue(sTaskStackChangedCalled);
- }
- assertTrue(sActivityBResumed);
+ activity.finish();
+ waitForCallback(latch);
}
@Test
@Presubmit
public void testTaskStackChanged_resumeWhilePausing() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
registerTaskStackChangedListener(new TaskStackListener() {
@Override
public void onTaskStackChanged() throws RemoteException {
- synchronized (sLock) {
- sTaskStackChangedCalled = true;
- }
+ latch.countDown();
}
});
- final Context context = getInstrumentation().getContext();
- context.startActivity(new Intent(context, ResumeWhilePausingActivity.class).addFlags(
- Intent.FLAG_ACTIVITY_NEW_TASK));
- UiDevice.getInstance(getInstrumentation()).waitForIdle();
-
- synchronized (sLock) {
- assertTrue(sTaskStackChangedCalled);
- }
+ startTestActivity(ResumeWhilePausingActivity.class);
+ waitForCallback(latch);
}
@Test
@@ -512,7 +493,7 @@ public class TaskStackChangedListenerTest {
try {
final boolean result = latch.await(WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
if (!result) {
- throw new RuntimeException("Timed out waiting for task stack change notification");
+ throw new AssertionError("Timed out waiting for task stack change notification");
}
} catch (InterruptedException e) {
}
@@ -569,19 +550,6 @@ public class TaskStackChangedListenerTest {
}
public static class ActivityA extends TestActivity {
-
- private boolean mActivityBLaunched = false;
-
- @Override
- protected void onPostResume() {
- super.onPostResume();
- if (mActivityBLaunched) {
- return;
- }
- mActivityBLaunched = true;
- finish();
- startActivity(new Intent(this, ActivityB.class));
- }
}
public static class ActivityB extends TestActivity {
@@ -589,10 +557,6 @@ public class TaskStackChangedListenerTest {
@Override
protected void onPostResume() {
super.onPostResume();
- synchronized (sLock) {
- sTaskStackChangedCalled = false;
- }
- sActivityBResumed = true;
finish();
}
}