Skip to content

Commit

Permalink
Kgalligan/2023 10 05/update stately (#4701)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpgalligan authored Oct 19, 2023
1 parent 6bcb831 commit 58a1313
Show file tree
Hide file tree
Showing 19 changed files with 8 additions and 507 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import app.cash.sqldelight.driver.native.wrapConnection
import co.touchlab.sqliter.DatabaseConfiguration
import co.touchlab.sqliter.DatabaseFileContext
import co.touchlab.sqliter.JournalMode
import co.touchlab.testhelp.concurrency.currentTimeMillis
import co.touchlab.testhelp.concurrency.sleep
import kotlin.native.concurrent.AtomicInt
import kotlin.native.concurrent.Worker
import kotlin.test.AfterTest
import kotlin.time.TimeSource

abstract class BaseConcurrencyTest {
fun countRows(myDriver: SqlDriver = driver): Long {
Expand Down Expand Up @@ -144,12 +144,12 @@ abstract class BaseConcurrencyTest {
}

internal fun waitFor(timeout: Long = 10_000, block: () -> Boolean) {
val start = currentTimeMillis()
val start = TimeSource.Monotonic.markNow()
var wasTimeout = false

while (!block() && !wasTimeout) {
sleep(200)
wasTimeout = (currentTimeMillis() - start) > timeout
wasTimeout = (TimeSource.Monotonic.markNow() - start).inWholeMilliseconds > timeout
}

if (wasTimeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package app.cash.sqldelight.paging3
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import kotlin.time.Duration.Companion.seconds

@OptIn(ExperimentalCoroutinesApi::class)
fun DbTest.runDbTest(body: suspend TestScope.() -> Unit) = runTest {
fun DbTest.runDbTest(body: suspend TestScope.() -> Unit) = runTest(timeout = 1000.seconds) {
val driver = provideDbDriver()
setup(driver)
body()
Expand Down
8 changes: 2 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ kotlinCoroutines = "1.7.3"
idea = "222.4459.24" # Flamingo | 2022.2.1 (see https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html)
androidxSqlite = "2.4.0"
schemaCrawler = "16.19.2"
stately = "1.2.5"
sqliter = "1.2.3"
testhelp = "0.6.9"
sqljs = "1.8.0"
paging-mpp = "3.1.1-0.3.1"
paging3 = "3.1.1"
Expand Down Expand Up @@ -79,11 +77,9 @@ schemaCrawler-sqlite = { module = "us.fatehi:schemacrawler-sqlite", version.ref

objectDiff = { module = "de.danielbechler:java-object-diff", version = "0.95" }
sqliter = { module = "co.touchlab:sqliter-driver", version.ref = "sqliter" }
stately-core = { module = "co.touchlab:stately-common", version.ref = "stately" }
stately-concurrency = { module = "co.touchlab:stately-concurrency", version.ref = "stately" }
stately-collections = { module = "co.touchlab:stately-collections", version.ref = "stately" }
stately-concurrency = { module = "co.touchlab:stately-concurrency", version = "2.0.5" }

This comment has been minimized.

Copy link
@darronschall

darronschall Oct 19, 2023

I have an iOS project using SQLDelight 2.1.0-Snapshot (for a bug fix not included in a release yet). I started running into build issues today that might be a result of this change moving the snapshot revision forward:

Showing Recent Messages
> Task :shared:compileKotlinIosSimulatorArm64 FAILED

Could not find "co.touchlab:stately-common" in [/Users/darron/Development/example-project-kmm, /Users/darron/.konan/klib, /Users/darron/.konan/kotlin-native-prebuilt-macos-aarch64-1.9.10/klib/common, /Users/darron/.konan/kotlin-native-prebuilt-macos-aarch64-1.9.10/klib/platform/ios_simulator_arm64]

This comment has been minimized.

Copy link
@darronschall

darronschall Oct 19, 2023

Explicitly adding stately-common to my project fixes the error, I think related to touchlab/Stately#93 (comment).

implementation("co.touchlab:stately-common:2.0.5")

I'll be curious if any other SQLDelight 2.1.0-SNAPSHOT users run into this same issue.

This comment has been minimized.

Copy link
@kpgalligan

kpgalligan Oct 19, 2023

Author Collaborator

@darronschall Are you using paging? If so, that's using cash paging 3.1.1-0.3.1, which uses Stately 1.2.5 source. The module structure changed in Stately 2, as Stately was primarily for the strict memory model. Paging also uses co.touchlab:stately-concurrency, but the 1.2.5, which depended on stately-common. There's a new version of app.cash.paging:paging-common which doesn't use Stately at all, but sqldelight is on 3.1.1-0.3.1, which does.

So, summary, if you're using paging in multiplatform, you'll need to include implementation("co.touchlab:stately-common:2.0.5"). I should probably add that explicitly to paging in sqldelight, now that I think about it...

This comment has been minimized.

Copy link
@darronschall

darronschall Oct 19, 2023

Thanks for the reply @kpgalligan!

I'm not using paging... I'm also using app.cash.sqldelight:coroutines-extensions, but didn't see anything there that might've caused the issue today.

This comment has been minimized.

Copy link
@kpgalligan

kpgalligan Oct 25, 2023

Author Collaborator

It seems like something has to be pulling in the reference to stately-common. The issue is that all stately modules in 1.x.x depended on stately-common, but most of common moved to what is now a reduced module stately-strict. There is still a stately-common but it's in the deprecated/legacy folder. If something references stately 1.x.x libraries, it says you also need stately-common, but if something else uses stately 2.x, Gradle prefers that, and those modules don't depend on stately-common. So, in summary, I'll dig through sqldelight again to make sure, but it's also possible that another library depends on stately 1.x.x and is causing the same issue. In any case, adding stately-common explicitly will "fix" it, but I would also like to nudge libraries using stately to update or remove it over time. It really existed for the old memory model, and still does a handful of other things that will likely be done by other libraries down the road.

This comment has been minimized.

Copy link
@darronschall

darronschall Oct 25, 2023

If it helps, this appears to be just an iOS problem, at least for me. I can run my Android app, and my shared library testReleaseUnitTest target, but I can't run the iOS app or iosSimulatorArm64Test because of the missing stately-common dependency. The gradle task ':shared:compileKotlinIosSimulatorArm64' is what's failing in my KMM project unless I explicitly add the stately-common dependency.


testhelp = { module = "co.touchlab:testhelp", version.ref = "testhelp" }
testhelp = { module = "co.touchlab:testhelp", version = "0.6.11" }
burst = { module = "com.squareup.burst:burst-junit4", version = "1.2.0" }
testParameterInjector = { module = "com.google.testparameterinjector:test-parameter-injector", version = "1.13" }

Expand Down
8 changes: 0 additions & 8 deletions runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ kotlin {
it.withWatchosArm64()
it.withWatchosX64()
it.withWatchosSimulatorArm64()

it.withLinuxX64()
it.withMingw()
}
Expand All @@ -43,13 +42,6 @@ kotlin {
jvmTest {
dependencies {
implementation libs.kotlin.test.junit
implementation libs.stately.collections
}
}
testableNativeTest {
dependencies {
implementation libs.stately.concurrency
implementation libs.stately.collections
}
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LogSqliteDriverTest {

private lateinit var driver: LogSqliteDriver
private lateinit var transacter: TransacterImpl
private val logs = LinkedList<String>()
private val logs = mutableListOf<String>()

@BeforeTest fun setup() {
driver = LogSqliteDriver(FakeSqlDriver()) { log ->
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ kotlin {
commonTest {
dependencies {
implementation libs.kotlin.test
implementation libs.stately.core
implementation libs.stately.concurrency
implementation "app.cash.sqldelight:runtime:${app.cash.sqldelight.VersionKt.VERSION}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ kotlin {
commonTest {
dependencies {
implementation libs.kotlin.test
implementation libs.stately.core
implementation libs.stately.concurrency
implementation "app.cash.sqldelight:runtime:${app.cash.sqldelight.VersionKt.VERSION}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import app.cash.sqldelight.ColumnAdapter
import app.cash.sqldelight.Query
import co.touchlab.stately.concurrency.AtomicInt
import co.touchlab.stately.concurrency.value
import co.touchlab.stately.freeze
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -25,7 +24,6 @@ class IntegrationTests {
val database = createSqlDatabase()

queryWrapper = QueryWrapper(database, NullableTypes.Adapter(ListAdapter))
queryWrapper.freeze()
personQueries = queryWrapper.personQueries
keywordsQueries = queryWrapper.sqliteKeywordsQueries
nullableTypesQueries = queryWrapper.nullableTypesQueries
Expand Down

0 comments on commit 58a1313

Please sign in to comment.