Skip to content

Commit 4025f68

Browse files
authored
feat!: room integration p1 MonitorStorage with fallback support (#137)
Phase 1 of database modernization - migrates MonitorStorage to Room using a copy-based migration strategy with automatic fallback. Migration approach: - Room uses new database file "RoomCalendarMonitor" - Data copied from legacy DB on first access (read-only) - Falls back to LegacyMonitorStorage if migration fails - Legacy database preserved for retry in future versions New files: - MonitorAlertEntity, MonitorAlertDao, MonitorDatabase (Room) - RoomMonitorStorage (implements MonitorStorageInterface) - LegacyMonitorStorage (extracted for fallback) - MigrationException (signals fallback trigger) Also: - Optimize UI test startup (suppress battery dialog) - Fix CI test result collection for scoped storage (API 30+) * refactor: room integration p1 MonitorStorage wip * ci: exclude allure results from dorny * test: maybe fix unit tests gradle * test: migration test * ci: hopefully make test results writting more consistent with internal storage * fix: potentially room migration * fix: cleanup and docs * test: new migration fix * test: fix migration test * docs: update * ci: fix dorny reporter * docs: update XmlRunListener javadoc * refactor: constantize col names * docs: update comment * docs: windows run from wsl to windows side via powershell * test(perf): dramaticall Speed up MainActivity and DismissedEventsActivity UI tests These tests were taking 15-60+ seconds each due to: - Ultron polling for 15 seconds when views weren't immediately ready - Battery optimization dialog blocking view assertions - No synchronization with background data loading operations - 300ms+ dialog dismissal delay on every test Changes: - Add suppressBatteryDialog option to UITestFixture to prevent battery optimization dialog via SharedPreference - Enable waitForAsyncTasks=true for tests with background data loading, using IdlingResource for proper Espresso synchronization - Skip dialog dismissal entirely when dialogs are pre-suppressed - Reduce default Ultron timeout from 15s to 5s (IdlingResource handles async waits, timeout is just a safety net) Expected improvement: 15-60s per test → 2-5s per test * test: do perf stuff for the other activites * fix: transaction wrap * test: test our actual code not some similar stuff * test: narrow broad exceptiosn bring and bring dialog wait down again * fix: init commit of version the uses clean new db instead of migrating the old one * refactor: cleaner update * fix: bug bot and narrow exception
1 parent 5cd9cce commit 4025f68

26 files changed

Lines changed: 1435 additions & 160 deletions

.cursor/rules/main-rules.mdc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ For new or updated copyright headers, use:
5656
Copyright (C) 2025 William Harris (wharris+cnplus@upscalews.com)
5757
```
5858

59-
(William inherited the application from Sergey Parshin in 2020)
59+
(William inherited the application from Sergey Parshin in 2020)
60+
61+
# Never Catch the broad Exception class
62+
63+
no catching Exception e. it can lead to hiding important bugs to catch. always do something more specific

.cursor/rules/wsl-unison-setup.mdc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,35 @@ Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data,
101101
The `scripts/bundle_or_skip.js` wrapper automatically detects and copies the pre-built bundle, skipping Metro on Windows. This is configured via `cliFile` in `android/app/build.gradle`.
102102

103103
See: https://github.com/nativewind/nativewind/issues/1667
104+
105+
## Running Android Instrumentation Tests
106+
107+
Android instrumentation tests (`connectedAndroidTest`) must be run from **Windows**, not WSL. The test runner communicates with the emulator over ports that don't work properly through WSL.
108+
109+
### From WSL Terminal (via PowerShell)
110+
111+
```bash
112+
# Wait for Unison sync after file changes (~15 seconds)
113+
sleep 15
114+
115+
# Run all tests for a specific class
116+
powershell.exe -Command 'cd C:\dev\CN\android; $env:JAVA_HOME = "C:\Program Files\Android\Android_Studio\jbr"; .\gradlew.bat :app:connectedX8664DebugAndroidTest "-Pandroid.testInstrumentationRunnerArguments.class=com.github.quarck.calnotify.monitorstorage.MonitorStorageMigrationTest"'
117+
118+
# Run all instrumentation tests
119+
powershell.exe -Command 'cd C:\dev\CN\android; $env:JAVA_HOME = "C:\Program Files\Android\Android_Studio\jbr"; .\gradlew.bat :app:connectedX8664DebugAndroidTest'
120+
```
121+
122+
### Important Notes
123+
124+
1. **Wait for sync**: Unison syncs every 10 seconds (no inotify on Windows mounts). Wait 15s after file changes before running tests.
125+
126+
2. **JAVA_HOME**: Must be set in PowerShell. Android Studio's bundled JBR is at `C:\Program Files\Android\Android_Studio\jbr`
127+
128+
3. **Test filtering**: Use `-Pandroid.testInstrumentationRunnerArguments.class=...`, NOT `--tests` (which doesn't work for `connectedAndroidTest`)
129+
130+
4. **Signature conflicts**: If you get `INSTALL_FAILED_UPDATE_INCOMPATIBLE`, uninstall the app first:
131+
```bash
132+
adb uninstall com.github.quarck.calnotify
133+
```
134+
135+
5. **Building APKs**: Can be done from either side, but running connected tests requires Windows.

.github/workflows/actions.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,8 @@ jobs:
809809
if: always() && steps.verify_results.outputs.has_results == 'true'
810810
with:
811811
name: 'Integration Tests (Shard ${{ matrix.shard }})'
812-
path: android/app/build/outputs/*.xml,android/app/build/outputs/**/*.xml
812+
# Exclude allure-results which contain non-JUnit XML files (use comma-separated paths)
813+
path: 'android/app/build/outputs/*.xml,android/app/build/outputs/androidTest-results/**/*.xml,android/app/build/outputs/connected/**/*.xml'
813814
reporter: java-junit
814815
fail-on-error: true
815816

android/app/build.gradle

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,19 @@ dependencies {
344344
// Jacoco
345345
androidTestImplementation 'org.jacoco:org.jacoco.core:0.8.12'
346346

347-
// Room POC (test only - verifying cr-sqlite compatibility)
347+
// Room database library
348348
// See docs/dev_todo/database_modernization_plan.md
349349
// Note: Room 2.7.0+ required for Kotlin 2.0.x metadata compatibility
350350
// https://developer.android.com/jetpack/androidx/releases/room
351351
def roomVersion = "2.8.4"
352-
androidTestImplementation "androidx.room:room-runtime:$roomVersion"
353-
androidTestImplementation "androidx.room:room-ktx:$roomVersion"
354-
androidTestImplementation "androidx.room:room-testing:$roomVersion"
355-
kspAndroidTest "androidx.room:room-compiler:$roomVersion"
352+
implementation "androidx.room:room-runtime:$roomVersion"
353+
implementation "androidx.room:room-ktx:$roomVersion"
354+
ksp "androidx.room:room-compiler:$roomVersion"
356355
// Room 2.8+ uses the new androidx.sqlite library
357-
androidTestImplementation "androidx.sqlite:sqlite:2.6.2"
358-
androidTestImplementation "androidx.sqlite:sqlite-framework:2.6.2"
356+
implementation "androidx.sqlite:sqlite:2.6.2"
357+
implementation "androidx.sqlite:sqlite-framework:2.6.2"
358+
// Room testing support
359+
androidTestImplementation "androidx.room:room-testing:$roomVersion"
359360
}
360361

361362
// https://reactnative.dev/docs/react-native-gradle-plugin
@@ -396,6 +397,15 @@ afterEvaluate {
396397
.withPathSensitivity(PathSensitivity.RELATIVE)
397398
.optional()
398399
}
400+
401+
// Wire KSP tasks (Room annotation processor)
402+
tasks.matching { it.name.matches('ksp.*Kotlin') }.configureEach { task ->
403+
task.dependsOn(autolinkTask)
404+
task.inputs.dir(autolinkingDir)
405+
.withPropertyName('autolinkingSources')
406+
.withPathSensitivity(PathSensitivity.RELATIVE)
407+
.optional()
408+
}
399409
}
400410
}
401411

android/app/src/androidTest/java/com/github/quarck/calnotify/database/poc/RoomPocDatabase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.content.Context
2323
import androidx.room.Database
2424
import androidx.room.Room
2525
import androidx.room.RoomDatabase
26+
import com.github.quarck.calnotify.database.CrSqliteRoomFactory
2627

2728
/**
2829
* POC Room database configured to use cr-sqlite via CrSqliteRoomFactory.

0 commit comments

Comments
 (0)