Modern Apps git

← Modern-Apps.git

games/nonogram: write mode changes on IO (#tests)

Commit
71e8647ae471d07bbdad53e7336553777b005644
Author
Vayun Mathur <[email protected]>
When
2026-11-15 00:14 UTC (21 days ago)
Parents
0d4e5ba
NonogramViewModelTest failed intermittently in full-class
runs (rapidMoves reload, then undo persisted): a DataStore
edit issued on viewModelScope's Main dispatcher can strand
the store's write lock when Main stops being pumped (tests
reset it between cases), wedging every later board write
behind it - the same mechanism that hung measure.

persist() already wrote boards on IO; setMarkMode and
setGameMode still launched their edits on Main. Move both
to Dispatchers.IO.

Verified: :games:nonogram:testDevUnitTest full module
111/111 green.

Diff

games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.ktindex c12532f267..be49e7116f 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/platform/NonogramViewModel.kt@@ -331,7 +331,10 @@ class NonogramViewModel(application: Application) : AndroidViewModel(application     override fun setMarkMode(mode: MarkMode) {         // In memory first, so a tap straight after switching uses the new mode.         _uiState.value = _uiState.value.copy(markMode = mode)-        viewModelScope.launch { dataStore.setMarkMode(mode) }+        // IO, not Main: a DataStore edit suspended on Main can strand+        // the store's write lock when Main stops being pumped (tests+        // reset it between cases), wedging every later board write.+        viewModelScope.launch(Dispatchers.IO) { dataStore.setMarkMode(mode) }     }      /**@@ -381,7 +384,7 @@ class NonogramViewModel(application: Application) : AndroidViewModel(application     }      override fun setGameMode(mode: GameMode) {-        viewModelScope.launch { dataStore.setGameMode(mode) }+        viewModelScope.launch(Dispatchers.IO) { dataStore.setGameMode(mode) }     }      override fun setReminderEnabled(enabled: Boolean) {