Modern Apps git

← Modern-Apps.git

email: cancel view model scope before closing test database

Commit
07e534246453f1f48577b5b5ec17f65f8f2bab32
Author
Vayun Mathur <[email protected]>
When
2026-11-17 02:44 UTC (19 days ago)
Parents
37573aa
NavigationTest closed the in-memory database while the ViewModel's accounts StateFlow (WhileSubscribed, 5s stop timeout) could still query it after the compose content left; that query threw 'connection pool has been closed' into a later test.

Cancel viewModelScope in tearDown before removing and closing the database.

Verified: TZ=UTC NavigationTest green.

Diff

email/src/test/java/com/vayunmathur/email/screens/NavigationTest.kt
diff --git a/email/src/test/java/com/vayunmathur/email/screens/NavigationTest.kt b/email/src/test/java/com/vayunmathur/email/screens/NavigationTest.ktindex e01b4a6e71..ade8552219 100644--- a/email/src/test/java/com/vayunmathur/email/screens/NavigationTest.kt+++ b/email/src/test/java/com/vayunmathur/email/screens/NavigationTest.kt@@ -19,9 +19,11 @@ import com.vayunmathur.email.data.EmailRepository import com.vayunmathur.email.platform.EmailViewModel import com.vayunmathur.email.platform.IntentState import com.vayunmathur.email.ui.MainContent+import androidx.lifecycle.viewModelScope import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test+import kotlinx.coroutines.cancel import kotlinx.coroutines.runBlocking import org.junit.Rule import org.junit.runner.RunWith@@ -63,6 +65,13 @@ class NavigationTest {     @AfterTest     fun close() {         IntentState.navigationRoute = null+        // Cancel the ViewModel's collectors before closing the database:+        // its accounts StateFlow (WhileSubscribed) can still query the+        // pool after the compose content is gone, and that query then+        // throws "connection pool has been closed" into a later test.+        if (::vm.isInitialized) {+            vm.viewModelScope.cancel()+        }         com.vayunmathur.library.util.databases.remove(EmailDatabase::class)         val field = EmailRepository::class.java.getDeclaredField("instance")         field.isAccessible = true