photos: await observed state in gallery selection and person-name tests
- Commit
e9a7f2e6e85f1d88ac1c9496397702a45936947f- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 02:44 UTC (19 days ago)
- Parents
911f350
galleryPageSelectionHeaderAppears asserted a count of nodes containing '1' at waitForIdle, which races the photos flow landing and depends on unrelated '1' texts; wait for the '1 selected' header itself instead. setPersonNamePersistsThroughDao read personsFlow().first() once after a viewModelScope launch, racing the async write and reading back stale 'Grace' after clearing; poll the DAO until each write is observed, as neighbouring tests already do. Verified: TZ=UTC both tests green.
Diff
photos/src/test/java/com/vayunmathur/photos/util/PhotosPagesRealRepoTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/util/PhotosPagesRealRepoTest.kt b/photos/src/test/java/com/vayunmathur/photos/util/PhotosPagesRealRepoTest.ktindex fab81e1031..c561d2481c 100644--- a/photos/src/test/java/com/vayunmathur/photos/util/PhotosPagesRealRepoTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/util/PhotosPagesRealRepoTest.kt@@ -203,8 +203,14 @@ class PhotosPagesRealRepoTest { com.vayunmathur.photos.ui.GalleryPage(stack(Route.Gallery), gallery, secureVm) } }- rule.waitForIdle()- assertTrue(rule.onAllNodesWithText("1", substring = true).fetchSemanticsNodes().size >= 2)+ // Wait for the selection header itself, not an idle instant: the+ // header appears once the photos flow lands, which waitForIdle does+ // not guarantee on a loaded box. (The old count of ">=2 nodes+ // containing 1" also depended on unrelated "1" texts in the grid.)+ rule.waitUntil(20_000) {+ rule.onAllNodesWithText("1 selected", substring = true).fetchSemanticsNodes().isNotEmpty()+ }+ assertTrue(rule.onAllNodesWithText("1 selected", substring = true).fetchSemanticsNodes().isNotEmpty()) Unit } }
photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3GalleryTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3GalleryTest.kt b/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3GalleryTest.ktindex aeb44ec68f..9959ef3ad2 100644--- a/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3GalleryTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3GalleryTest.kt@@ -318,16 +318,28 @@ class PhotosSlice3GalleryTest { Person(centroid = ByteArray(8), faceCount = 0, name = null), ) vm.setPersonName(personId, "Grace")- // setPersonName launches without an IO dispatcher so Room executes the- // write itself: the DAO row shows the name; with no faces the cluster- // still projects to nothing.+ // setPersonName launches in viewModelScope, so the write lands+ // asynchronously: poll the DAO until it is observed instead of+ // reading the flow once (a single first() races the launch and,+ // for the clear below, reads back the stale "Grace").+ // With no faces the cluster still projects to nothing. val people = vm.people.first { true } assertTrue(people.none { it.id == personId })- val name = db.faceDao().personsFlow().first().first { it.id == personId }.name+ var name: String? = null+ var tries = 0+ while (name != "Grace" && tries < 250) {+ name = db.faceDao().personsFlow().first().first { it.id == personId }.name+ if (name != "Grace") { kotlinx.coroutines.delay(20); tries++ }+ } assertEquals("Grace", name) // Clearing the name persists too. vm.setPersonName(personId, null)- val cleared = db.faceDao().personsFlow().first().first { it.id == personId }.name+ var cleared: String? = "unset"+ tries = 0+ while (cleared != null && tries < 250) {+ cleared = db.faceDao().personsFlow().first().first { it.id == personId }.name+ if (cleared != null) { kotlinx.coroutines.delay(20); tries++ }+ } assertEquals(null, cleared) }