Bugfix:com.android.server.nearby.fastpair.cache.FastPairCacheManagerTest#getAllInfo fail
Test fails on MTS but works fine on Eng atest.
Ideally, save one DiscoveryItem, the size should be 1, save two items,
the size should be 2.
But in Eng atest, the result shows that there seems to be an extra DiscoveryItem stored in the
database. After investigation, found that the extra one is from another test case: saveRetrieveInfo, where another DiscoveryItem was saved to the database.
Since tests can be run in parallel, sometimes one test may run before or after another. So, it may have different test results.
Combining the two tests into a single test and letting them run sequentially solved the problem.
Bug: 238394647
Test: unit test
Change-Id: I9536ce6ad4fff78188f0ceb325d275b05aa47da4
Merged-In: I9536ce6ad4fff78188f0ceb325d275b05aa47da4
diff --git a/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java b/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java
index adae97d..fdda6f7 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java
@@ -81,30 +81,20 @@
Context mContext = ApplicationProvider.getApplicationContext();
when(mDiscoveryItem.getCopyOfStoredItem()).thenReturn(mStoredDiscoveryItem);
when(mDiscoveryItem.getTriggerId()).thenReturn(MODEL_ID);
-
- FastPairCacheManager fastPairCacheManager = new FastPairCacheManager(mContext);
- fastPairCacheManager.saveDiscoveryItem(mDiscoveryItem);
- assertThat(fastPairCacheManager.getStoredDiscoveryItem(MODEL_ID).getAppName())
- .isEqualTo(APP_NAME);
- }
-
- @Test
- @SdkSuppress(minSdkVersion = 32, codeName = "T")
- public void getAllInfo() {
- Context mContext = ApplicationProvider.getApplicationContext();
- when(mDiscoveryItem.getCopyOfStoredItem()).thenReturn(mStoredDiscoveryItem);
- when(mDiscoveryItem.getTriggerId()).thenReturn(MODEL_ID);
when(mDiscoveryItem2.getCopyOfStoredItem()).thenReturn(mStoredDiscoveryItem2);
when(mDiscoveryItem2.getTriggerId()).thenReturn(MODEL_ID2);
FastPairCacheManager fastPairCacheManager = new FastPairCacheManager(mContext);
fastPairCacheManager.saveDiscoveryItem(mDiscoveryItem);
-
- assertThat(fastPairCacheManager.getAllSavedStoreDiscoveryItem()).hasSize(2);
+ assertThat(fastPairCacheManager.getStoredDiscoveryItem(MODEL_ID).getAppName())
+ .isEqualTo(APP_NAME);
+ assertThat(fastPairCacheManager.getAllSavedStoreDiscoveryItem()).hasSize(1);
fastPairCacheManager.saveDiscoveryItem(mDiscoveryItem2);
-
- assertThat(fastPairCacheManager.getAllSavedStoreDiscoveryItem()).hasSize(3);
+ assertThat(fastPairCacheManager.getStoredDiscoveryItem(MODEL_ID2).getAppName())
+ .isEqualTo(APP_NAME);
+ assertThat(fastPairCacheManager.getAllSavedStoreDiscoveryItem()).hasSize(2);
+ fastPairCacheManager.cleanUp();
}
@Test