Use notification posted latch for autogroup test
Use the notification posted count instead of ranking because ranking is also updated on post and causes flaky tests.
Flag: EXEMPT bug fix
Test: atest android.app.notification.current.cts.NotificationManagerTest
Bug: 438270862
Change-Id: I7a7c7fe4198480e40e3dccfc3377c065b4ccd2a1
diff --git a/tests/tests/notification/src/android/app/notification/current/cts/NotificationManagerTest.java b/tests/tests/notification/src/android/app/notification/current/cts/NotificationManagerTest.java
index c4a1702..8fad9b7 100644
--- a/tests/tests/notification/src/android/app/notification/current/cts/NotificationManagerTest.java
+++ b/tests/tests/notification/src/android/app/notification/current/cts/NotificationManagerTest.java
@@ -1847,8 +1847,12 @@
private void testAutogrouping_forceGrouping_common(boolean summaryOnly) throws Exception {
mListener = mNotificationHelper.enableListener(STUB_PACKAGE_NAME);
assertNotNull(mListener);
- CountDownLatch postingLatch = mListener.setPostedCountDown(5);
- CountDownLatch rerankLatch = mListener.setRankingUpdateCountDown(5);
+ final int numNotificationsInAutogroup = 5;
+ // Expect 2x number of posted callback because NMS will notify listeners
+ // when notifications were forced grouped through onNotificationPosted
+ final int numExpectedPostedCount = 2 * numNotificationsInAutogroup;
+ CountDownLatch postingLatch = mListener.setPostedCountDown(numExpectedPostedCount);
+ CountDownLatch rerankLatch;
String testGroup = "testGroup";
sendNotification(910, testGroup, summaryOnly, R.drawable.black, false, null);
@@ -1864,8 +1868,7 @@
// Wait until all the notifications, including the autogroup, are posted and grouped.
postingLatch.await(TIMEOUT_FORCE_REGROUP_MS, TimeUnit.MILLISECONDS);
- rerankLatch.await(TIMEOUT_FORCE_REGROUP_MS, TimeUnit.MILLISECONDS);
- assertNotificationCount(5);
+ assertNotificationCount(numNotificationsInAutogroup);
assertAllPostedNotificationsAutogrouped();
// Cancel all autogrouped notifications
@@ -1880,8 +1883,8 @@
assertAllPostedNotificationsAutogrouped();
}
// Autogroup summary should be canceled
- postingLatch.await(400, TimeUnit.MILLISECONDS);
- rerankLatch.await(400, TimeUnit.MILLISECONDS);
+ removedLatch = mListener.setRemovedCountDown(1);
+ removedLatch.await(400, TimeUnit.MILLISECONDS);
assertNotificationCount(0);
}