Modern Apps git

← Modern-Apps.git

nonogram: poll VM-test conditions in real time; widen clue-fit slack (#ux-audit)

Commit
76a9f904a45767b31b2b8dda9bc74f4944bc2265
Author
Vayun Mathur <[email protected]>
When
2026-11-13 08:41 UTC (23 days ago)
Parents
d30d065
Follow-up to the previous test commits.

- NonogramViewModelTest.await() timed out against
  System.currentTimeMillis(), which Robolectric replaces with its own
  clock in test code; it can run far ahead of real time, so an await
  could give up within ~0.1s of real time while a background write was
  still landing (seen as "timed out: undo persisted" after 0.15s, and
  likely behind reminderActionsUpdateState's failure on main). It now
  polls a fixed number of LockSupport.parkNanos steps (~20s real).
- cluesFitTheirSlotsAtLargeFontScale: the Column that stacks a full
  gutter rounds each slot to whole pixels, which can squeeze the slot
  nearest the edge by a pixel or two below the line height. The check
  now allows 25% slack - still far below the 2x overflow the old `.sp`
  sizing produced at 200% font scale.

Diff

games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.ktindex b89c8311a9..0b3aa1f7e4 100644--- a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt@@ -5,6 +5,7 @@ import androidx.test.core.app.ApplicationProvider import com.vayunmathur.games.nonogram.data.GameMode import com.vayunmathur.games.nonogram.data.MarkMode import com.vayunmathur.games.nonogram.data.STARTING_HEARTS+import java.util.concurrent.locks.LockSupport import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.first@@ -55,11 +56,20 @@ class NonogramViewModelTest {      private companion object {         const val RETRIES = 20+        const val AWAIT_STEPS = 800+        const val AWAIT_STEP_NANOS = 25_000_000L     } +    /**+     * Polls [cond] for up to ~20s of real time.+     *+     * Counted in steps rather than against System.currentTimeMillis(): Robolectric substitutes its+     * own clock for test code, which can run far ahead of real time, so a clock-based deadline could+     * give up within milliseconds while a background write was still landing. parkNanos is real.+     */     private fun await(desc: String, cond: () -> Boolean) {-        val deadline = System.currentTimeMillis() + 20_000-        while (System.currentTimeMillis() < deadline && !cond()) Thread.sleep(25)+        var steps = 0+        while (steps++ < AWAIT_STEPS && !cond()) LockSupport.parkNanos(AWAIT_STEP_NANOS)         assertTrue(cond(), "timed out: $desc")     } 
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.ktindex 2e747b5731..9f9759d945 100644--- a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt@@ -317,9 +317,10 @@ class NonogramScreensTest {             val text = r.layoutInput.text.text             // Checked on the resolved style rather than measured glyphs, which Robolectric's             // stand-in text metrics do not report faithfully. The slot is the Text's max height;-            // 1px of tolerance covers rounding it to whole pixels. The old `.sp` sizing fails both-            // checks at 200%: its font and line box were each twice what the slot was fitted for.-            val slotPx = r.layoutInput.constraints.maxHeight + 1f+            // A quarter of slack covers whole-pixel rounding, which can squeeze the slot nearest a+            // full gutter by a pixel or two. The old `.sp` sizing fails both checks at 200%: its+            // font and line box were each twice what the slot was fitted for.+            val slotPx = r.layoutInput.constraints.maxHeight * 1.25f + 1f             val fontPx = with(r.layoutInput.density) { r.layoutInput.style.fontSize.toPx() }             val linePx = with(r.layoutInput.density) { r.layoutInput.style.lineHeight.toPx() }             assertTrue(fontPx <= slotPx, "clue '$text' is ${fontPx}px in a ${slotPx}px slot")