mirror of
https://github.com/Monkopedia/rouse-context.git
synced 2026-11-22 21:29:43 +00:00
AuditHistoryViewModelRoomTest pointed Dispatchers.Main at the shared Dispatchers.IO pool and tore down with a fire-and-forget testScope.coroutineContext[Job]?.cancel() (no join) before resetMain(), and never cancelled the VM's viewModelScope at all. A viewModelScope coroutine (the stateIn upstream / Room flow collector) could therefore still be dispatching on Main when resetMain() ran, and could outlive it. Unit tests run in a single JVM (no forkEvery), so the leaked Main override surfaces as an IllegalStateException from kotlinx.coroutines.test's internal TestMainDispatcher in a random later test's setMain. That is the moving-target flake in #376 (CI run 27476494784 attempt 1: failures in AuditHistoryViewModelRoomTest.kt:83 at resetMain and, downstream, OnboardingViewModelTest). Fix: - Add MainDispatcherRule: pairs setMain/resetMain in a TestRule so the reset always runs in a finally around the whole test. - Route Main to a dedicated single-thread executor the test owns (not shared IO), preserving the real cross-thread scheduler Room's invalidation tracker needs while making the dispatcher drainable. - Own the VM in a ViewModelStore; in tearDown cancel viewModelScope via clear(), then shutdown()+awaitTermination() the executor so Main is fully quiescent (worker thread dead) before the rule's resetMain() fires. Join the warmup collector with cancelAndJoin on the runBlocking scope. Co-authored-by: Monkopedia <monkopedia@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| screenshots | ||
| src | ||
| build.gradle.kts | ||
| google-services.json | ||
| proguard-rules.pro | ||