Skip to content

Commit 2df1a00

Browse files
authored
Enable build scans (#224)
* Enable build scans * Also enable for docs build * Consistently cancel turbine * Make checkpoint during upload test more reliable * Reformat
2 parents 2946728 + 77d4f5f commit 2df1a00

File tree

8 files changed

+87
-14
lines changed

8 files changed

+87
-14
lines changed

.github/workflows/docs-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
validate-wrappers: true
3232
- name: Build Docs
3333
run: |
34-
./gradlew \
34+
./gradlew --scan \
3535
--no-configuration-cache \
3636
-PGITHUB_PUBLISH_TOKEN=${{ secrets.GITHUB_TOKEN }} \
3737
dokkaGenerate

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
- name: Build and run tests with Gradle
4545
run: |
46-
./gradlew \
46+
./gradlew --scan \
4747
${{ matrix.targets }}
4848
shell: bash
4949

build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ dokka {
7575
moduleName.set("PowerSync Kotlin")
7676
}
7777

78+
develocity {
79+
val isPowerSyncCI = System.getenv("GITHUB_REPOSITORY") == "powersync-ja/powersync-kotlin"
80+
81+
buildScan {
82+
// We can't know if everyone running this build has accepted the TOS, but we've accepted
83+
// them for our CI.
84+
if (isPowerSyncCI) {
85+
termsOfUseUrl.set("https://gradle.com/help/legal-terms-of-use")
86+
termsOfUseAgree.set("yes")
87+
}
88+
89+
// Only upload build scan if the --scan parameter is set
90+
publishing.onlyIf { false }
91+
}
92+
}
93+
7894
// Serve the generated Dokka documentation using a simple HTTP server
7995
// File changes are not watched here
8096
tasks.register("serveDokka") {

core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import io.kotest.matchers.shouldNotBe
3232
import io.kotest.matchers.string.shouldContain
3333
import kotlinx.coroutines.CompletableDeferred
3434
import kotlinx.coroutines.DelicateCoroutinesApi
35+
import kotlinx.coroutines.Dispatchers
36+
import kotlinx.coroutines.withContext
3537
import kotlinx.serialization.json.jsonObject
3638
import kotlinx.serialization.json.jsonPrimitive
3739
import kotlin.test.Test
@@ -411,8 +413,8 @@ abstract class BaseSyncIntegrationTest(
411413
db2.disconnect()
412414
turbine2.waitFor { !it.connecting }
413415

414-
turbine1.cancel()
415-
turbine2.cancel()
416+
turbine1.cancelAndIgnoreRemainingEvents()
417+
turbine2.cancelAndIgnoreRemainingEvents()
416418
}
417419
}
418420

@@ -433,7 +435,7 @@ abstract class BaseSyncIntegrationTest(
433435
database.disconnect()
434436
turbine.waitFor { !it.connecting }
435437

436-
turbine.cancel()
438+
turbine.cancelAndIgnoreRemainingEvents()
437439
}
438440
}
439441

@@ -449,7 +451,7 @@ abstract class BaseSyncIntegrationTest(
449451
database.connect(connector, 1000L, retryDelayMs = 5000, options = options)
450452
turbine.waitFor { it.connecting }
451453

452-
turbine.cancel()
454+
turbine.cancelAndIgnoreRemainingEvents()
453455
}
454456
}
455457

@@ -482,10 +484,21 @@ abstract class BaseSyncIntegrationTest(
482484
turbineScope {
483485
val turbine = database.currentStatus.asFlow().testIn(this)
484486
syncLines.send(SyncLine.KeepAlive(1234))
485-
turbine.waitFor { it.connected && !it.uploading }
487+
turbine.waitFor { it.connected }
486488
turbine.cancelAndIgnoreRemainingEvents()
487489
}
488490

491+
// Wait for the first upload task triggered when connecting to be complete.
492+
withContext(Dispatchers.Default) {
493+
waitFor {
494+
assertNotNull(
495+
logWriter.logs.find {
496+
it.message.contains("crud upload: notify completion")
497+
},
498+
)
499+
}
500+
}
501+
489502
database.execute("INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)", listOf("local", "[email protected]"))
490503

491504
expectUserRows(1)
@@ -650,7 +663,7 @@ abstract class BaseSyncIntegrationTest(
650663
turbine.waitFor { !it.connected }
651664
connector.cachedCredentials shouldBe null
652665

653-
turbine.cancel()
666+
turbine.cancelAndIgnoreRemainingEvents()
654667
}
655668
}
656669

@@ -686,7 +699,7 @@ abstract class BaseSyncIntegrationTest(
686699
// Should retry, and the second fetchCredentials call will work
687700
turbine.waitFor { it.connected }
688701

689-
turbine.cancel()
702+
turbine.cancelAndIgnoreRemainingEvents()
690703
}
691704
}
692705
}
@@ -740,7 +753,7 @@ class NewSyncIntegrationTest : BaseSyncIntegrationTest(true) {
740753

741754
turbine.waitFor { it.connected }
742755
fetchCredentialsCount shouldBe 2
743-
turbine.cancel()
756+
turbine.cancelAndIgnoreRemainingEvents()
744757
}
745758
}
746759

core/src/commonIntegrationTest/kotlin/com/powersync/testutils/TestUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import co.touchlab.kermit.LogWriter
77
import co.touchlab.kermit.Logger
88
import co.touchlab.kermit.Severity
99
import co.touchlab.kermit.TestConfig
10-
import co.touchlab.kermit.TestLogWriter
1110
import com.powersync.DatabaseDriverFactory
11+
import com.powersync.PowerSyncTestLogWriter
1212
import com.powersync.TestConnector
1313
import com.powersync.bucket.WriteCheckpointData
1414
import com.powersync.bucket.WriteCheckpointResponse
@@ -73,8 +73,8 @@ internal class ActiveDatabaseTest(
7373
lateinit var database: PowerSyncDatabaseImpl
7474

7575
val logWriter =
76-
TestLogWriter(
77-
loggable = Severity.Debug,
76+
PowerSyncTestLogWriter(
77+
loggable = Severity.Verbose,
7878
)
7979
val logger =
8080
Logger(

core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import io.ktor.utils.io.ByteReadChannel
3636
import io.ktor.utils.io.readUTF8Line
3737
import kotlinx.coroutines.CancellationException
3838
import kotlinx.coroutines.CompletableDeferred
39+
import kotlinx.coroutines.CoroutineName
3940
import kotlinx.coroutines.CoroutineScope
4041
import kotlinx.coroutines.Job
4142
import kotlinx.coroutines.NonCancellable
@@ -122,7 +123,7 @@ internal class SyncStream(
122123
}
123124

124125
fun triggerCrudUploadAsync(): Job =
125-
uploadScope.launch {
126+
uploadScope.launch(CoroutineName("triggerCrudUploadAsync")) {
126127
val thisIteration = PendingCrudUpload(CompletableDeferred())
127128
var holdingUploadLock = false
128129

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.powersync
2+
3+
import co.touchlab.kermit.ExperimentalKermitApi
4+
import co.touchlab.kermit.LogWriter
5+
import co.touchlab.kermit.Severity
6+
import co.touchlab.kermit.TestLogWriter.LogEntry
7+
import kotlinx.atomicfu.locks.reentrantLock
8+
import kotlinx.atomicfu.locks.withLock
9+
10+
/**
11+
* A version of the `TestLogWriter` from Kermit that uses a mutex around logs instead of throwing
12+
* for concurrent access.
13+
*/
14+
@OptIn(ExperimentalKermitApi::class)
15+
class PowerSyncTestLogWriter(
16+
private val loggable: Severity,
17+
) : LogWriter() {
18+
private val lock = reentrantLock()
19+
private val _logs = mutableListOf<LogEntry>()
20+
21+
val logs: List<LogEntry>
22+
get() = lock.withLock { _logs.toList() }
23+
24+
override fun isLoggable(
25+
tag: String,
26+
severity: Severity,
27+
): Boolean = severity.ordinal >= loggable.ordinal
28+
29+
override fun log(
30+
severity: Severity,
31+
message: String,
32+
tag: String,
33+
throwable: Throwable?,
34+
) {
35+
lock.withLock {
36+
_logs.add(LogEntry(severity, message, tag, throwable))
37+
}
38+
}
39+
}

settings.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ dependencyResolutionManagement {
1515
}
1616
}
1717

18+
plugins {
19+
id("com.gradle.develocity") version "4.1"
20+
}
21+
1822
rootProject.name = "powersync-root"
1923

2024
include(":core")

0 commit comments

Comments
 (0)