From 97950d0b6c7babc2edaa6181a98f4063f6fd02e3 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Tue, 30 Jun 2026 20:20:30 -0500 Subject: [PATCH] fix(test): stop closing the in-memory DB under the still-active AccountSettings VM AccountSettingsScreenTest closed its Room in-memory database in @After while the ViewModel's `settings` Flow (kept alive by stateIn/WhileSubscribed) was still querying it. That race surfaced as "connection pool has been closed" (API 29) and "attempt to re-open an already-closed object" (API 36) on the slower CI legs, while passing on 30-35/37 and locally. Leave the in-memory DB unclosed (reclaimed with the test process) so the lingering flow never hits a closed connection. Co-Authored-By: Claude Opus 4.8 --- .../ui/settings/AccountSettingsScreenTest.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/kotlin/org/libremail/ui/settings/AccountSettingsScreenTest.kt b/app/src/androidTest/kotlin/org/libremail/ui/settings/AccountSettingsScreenTest.kt index 41a35ad..d4f26b7 100644 --- a/app/src/androidTest/kotlin/org/libremail/ui/settings/AccountSettingsScreenTest.kt +++ b/app/src/androidTest/kotlin/org/libremail/ui/settings/AccountSettingsScreenTest.kt @@ -12,7 +12,6 @@ import androidx.room.Room import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.runBlocking -import org.junit.After import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -47,16 +46,15 @@ class AccountSettingsScreenTest { smtp = ServerConfig("smtp.example.com", 465, MailSecurity.SSL_TLS), ) - private lateinit var db: LibreMailDatabase - - @After - fun tearDown() = db.close() - private fun string(resId: Int) = composeTestRule.activity.getString(resId) private fun setContent(): AccountSettingsRepository { val context = ApplicationProvider.getApplicationContext() - db = Room.inMemoryDatabaseBuilder(context, LibreMailDatabase::class.java).build() + // Intentionally not closed in an @After: the ViewModel's `settings` Room Flow (kept alive by + // stateIn/WhileSubscribed) keeps querying after the test body, so closing the in-memory DB out + // from under it races and crashes ("connection pool has been closed"). The DB is reclaimed with + // the test process. + val db = Room.inMemoryDatabaseBuilder(context, LibreMailDatabase::class.java).build() val repository = AccountSettingsRepository(db.accountSettingsDao()) runBlocking { db.accountDao().upsert(account.toEntity()) // FK parent for the account_settings row