diff --git a/persistence/src/androidInstrumentedTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt b/persistence/src/androidInstrumentedTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt index 4014b01643e..cfbb214b97b 100644 --- a/persistence/src/androidInstrumentedTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt +++ b/persistence/src/androidInstrumentedTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt @@ -26,7 +26,6 @@ import com.wire.kalium.persistence.db.PlatformDatabaseData import com.wire.kalium.persistence.db.globalDatabaseProvider import com.wire.kalium.persistence.util.FileNameUtil import com.wire.kalium.util.KaliumDispatcherImpl -import kotlinx.coroutines.test.TestDispatcher actual abstract class GlobalDBBaseTest { @@ -35,7 +34,7 @@ actual abstract class GlobalDBBaseTest { context.deleteDatabase(FileNameUtil.globalDBName()) } - actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder = globalDatabaseProvider( + actual fun createDatabase(): GlobalDatabaseBuilder = globalDatabaseProvider( platformDatabaseData = PlatformDatabaseData(ApplicationProvider.getApplicationContext()), queriesContext = KaliumDispatcherImpl.unconfined, passphrase = GlobalDatabaseSecret("test_db_secret".toByteArray()), diff --git a/persistence/src/androidUnitTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt b/persistence/src/androidUnitTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt index 6bdb61a7dc9..df3c50b7c8d 100644 --- a/persistence/src/androidUnitTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt +++ b/persistence/src/androidUnitTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt @@ -26,7 +26,7 @@ actual abstract class GlobalDBBaseTest { TODO("Not yet implemented") } - actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder { + actual fun createDatabase(): GlobalDatabaseBuilder { TODO("Not yet implemented") } } diff --git a/persistence/src/appleTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt b/persistence/src/appleTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt index 45e248a0604..48d3e69d0d2 100644 --- a/persistence/src/appleTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt +++ b/persistence/src/appleTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt @@ -25,7 +25,6 @@ import com.wire.kalium.persistence.db.StorageData import com.wire.kalium.persistence.db.globalDatabaseProvider import com.wire.kalium.persistence.util.FileNameUtil import kotlinx.coroutines.test.StandardTestDispatcher -import kotlinx.coroutines.test.TestDispatcher import platform.Foundation.NSCachesDirectory import platform.Foundation.NSFileManager import platform.Foundation.NSUserDomainMask @@ -38,7 +37,7 @@ actual abstract class GlobalDBBaseTest { deleteDatabase(FileNameUtil.globalDBName(), storePath) } - actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder { + actual fun createDatabase(): GlobalDatabaseBuilder { return globalDatabaseProvider( PlatformDatabaseData(StorageData.FileBacked(storePath)), StandardTestDispatcher(), null, false ) diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/db/GlobalDatabaseBuilder.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/db/GlobalDatabaseBuilder.kt index 163d0373215..180f339779c 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/db/GlobalDatabaseBuilder.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/db/GlobalDatabaseBuilder.kt @@ -42,7 +42,7 @@ value class GlobalDatabaseSecret(val value: ByteArray) class GlobalDatabaseBuilder internal constructor( private val sqlDriver: SqlDriver, private val platformDatabaseData: PlatformDatabaseData, - protected val queriesContext: CoroutineContext = KaliumDispatcherImpl.io + private val queriesContext: CoroutineContext = KaliumDispatcherImpl.io ) { internal val database: GlobalDatabase = GlobalDatabase( diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt index 3864d494494..e4b88696644 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt @@ -19,10 +19,8 @@ package com.wire.kalium.persistence import com.wire.kalium.persistence.db.GlobalDatabaseBuilder -import kotlinx.coroutines.test.StandardTestDispatcher -import kotlinx.coroutines.test.TestDispatcher expect abstract class GlobalDBBaseTest() { fun deleteDatabase() - fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder + fun createDatabase(): GlobalDatabaseBuilder } diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAOTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAOTest.kt index 3c948c3f144..befaae85ff9 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAOTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAOTest.kt @@ -51,18 +51,15 @@ class ServerConfigurationDAOTest : GlobalDBBaseTest() { private val config3 = newServerConfig(id = 3) lateinit var globalDatabaseBuilder: GlobalDatabaseBuilder - private val dispatcher: TestDispatcher = StandardTestDispatcher() @BeforeTest fun setup() { - Dispatchers.setMain(dispatcher) - globalDatabaseBuilder = createDatabase(dispatcher) + globalDatabaseBuilder = createDatabase() } @AfterTest fun nuke() { deleteDatabase() - Dispatchers.resetMain() } @Test diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/globalDB/AccountsDAOTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/globalDB/AccountsDAOTest.kt index d93b52a0f79..d5d55507e5e 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/globalDB/AccountsDAOTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/globalDB/AccountsDAOTest.kt @@ -29,10 +29,15 @@ import com.wire.kalium.persistence.db.GlobalDatabaseBuilder import com.wire.kalium.persistence.model.LogoutReason import com.wire.kalium.persistence.model.ServerConfigEntity import com.wire.kalium.persistence.model.SsoIdEntity +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher +import kotlinx.coroutines.test.TestCoroutineScheduler import kotlinx.coroutines.test.TestDispatcher +import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.runTest +import kotlinx.coroutines.test.setMain +import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals @@ -42,12 +47,11 @@ import kotlin.test.assertNull class AccountsDAOTest : GlobalDBBaseTest() { lateinit var globalDatabaseBuilder: GlobalDatabaseBuilder - private val dispatcher: TestDispatcher = StandardTestDispatcher() @BeforeTest fun setUp() = runTest { deleteDatabase() - globalDatabaseBuilder = createDatabase(dispatcher) + globalDatabaseBuilder = createDatabase() with(SERVER_CONFIG) { globalDatabaseBuilder.serverConfigurationDAO.insert( diff --git a/persistence/src/jsTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt b/persistence/src/jsTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt index 6bdb61a7dc9..edb29062eb1 100644 --- a/persistence/src/jsTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt +++ b/persistence/src/jsTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt @@ -19,14 +19,13 @@ package com.wire.kalium.persistence import com.wire.kalium.persistence.db.GlobalDatabaseBuilder -import kotlinx.coroutines.test.TestDispatcher actual abstract class GlobalDBBaseTest { actual fun deleteDatabase() { TODO("Not yet implemented") } - actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder { + actual fun createDatabase(): GlobalDatabaseBuilder { TODO("Not yet implemented") } } diff --git a/persistence/src/jvmTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt b/persistence/src/jvmTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt index f5af3f1e099..64f8f267ed1 100644 --- a/persistence/src/jvmTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt +++ b/persistence/src/jvmTest/kotlin/com/wire/kalium/persistence/GlobalDBBaseTest.kt @@ -27,13 +27,14 @@ import kotlinx.coroutines.test.TestDispatcher import java.nio.file.Files actual abstract class GlobalDBBaseTest { + private val dispatcher: TestDispatcher = StandardTestDispatcher() private val databaseFile = Files.createTempDirectory("test-storage").toFile().resolve("test-kalium.db") actual fun deleteDatabase() { databaseFile.delete() } - actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder { + actual fun createDatabase(): GlobalDatabaseBuilder { return globalDatabaseProvider( platformDatabaseData = PlatformDatabaseData( StorageData.FileBacked(databaseFile)