keyboard: wait for the settings mirror in the defaults test
- Commit
0811e321ada32b90805f6aef90ce9a3ca0bc2b01- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 19:58 UTC (28 days ago)
- Parents
c64e9c6
The settings test wrote kb_active_layout with a suspending DataStore edit and immediately read it back through KeyboardSettings.load, whose synchronous getters read an eagerly-collected StateFlow mirror of the store. The mirror catches up asynchronously after an edit commits; on the loaded CI box it had not caught up, and the layout read back as the en_qwerty default instead of de_qwertz (run 8f356294). The test now polls load() until the written layout is visible (10s bound) before asserting. No production change: the mirror's eventual consistency is the documented DataStoreUtils contract and the IME reads settings at bind time, not mid-edit. Verified locally on devvm24805: :keyboard:testDevUnitTest for PlatformRoboTest green.
Diff
keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.ktindex be303b9acb..a98c5c7282 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/util/PlatformRoboTest.kt@@ -40,7 +40,17 @@ class PlatformRoboTest { ds.setBoolean(KeyboardSettings.Keys.HAPTIC, false) ds.setDouble(KeyboardSettings.Keys.KEY_HEIGHT, 1.2) ds.setString(KeyboardSettings.Keys.ACTIVE_LAYOUT, "de_qwertz")- val loaded = KeyboardSettings.load(ds)+ // DataStoreUtils' synchronous getters read an eagerly-collected+ // mirror of the store; the mirror catches up asynchronously after+ // a suspending edit commits, so poll instead of assuming the very+ // next load sees the write (on a loaded CI box it did not, and the+ // layout read back as the default).+ var loaded = KeyboardSettings.load(ds)+ val deadline = System.currentTimeMillis() + 10_000+ while (loaded.activeLayoutId != "de_qwertz" && System.currentTimeMillis() < deadline) {+ Thread.sleep(20)+ loaded = KeyboardSettings.load(ds)+ } assertTrue(loaded.sound) assertFalse(loaded.haptic) assertEquals(1.2f, loaded.keyHeightScale)