Skip to content

Commit 290b306

Browse files
committed
Fix sync progress test
1 parent 17cd768 commit 290b306

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## unreleased
4+
5+
* Report real-time progress information about downloads through `SyncStatus.downloadProgress`.
6+
* Compose: Add `composeState()` extension method on `SyncStatus`.
7+
38
## 1.0.0-BETA31
49

510
* Added helpers for Attachment syncing.

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import com.powersync.bucket.BucketPriority
77
import com.powersync.bucket.Checkpoint
88
import com.powersync.bucket.OpType
99
import com.powersync.bucket.OplogEntry
10+
import com.powersync.testutils.ActiveDatabaseTest
11+
import com.powersync.testutils.databaseTest
1012
import com.powersync.testutils.waitFor
1113
import kotlinx.coroutines.channels.Channel
1214
import kotlinx.coroutines.test.runTest
@@ -17,7 +19,7 @@ import kotlin.test.assertFalse
1719
import kotlin.test.assertNull
1820
import kotlin.test.assertTrue
1921

20-
class SyncProgressTest : BaseInMemorySyncTest() {
22+
class SyncProgressTest {
2123
private var lastOpId = 0
2224

2325
@BeforeTest
@@ -37,7 +39,7 @@ class SyncProgressTest : BaseInMemorySyncTest() {
3739
count = count,
3840
)
3941

40-
private suspend fun addDataLine(
42+
private suspend fun ActiveDatabaseTest.addDataLine(
4143
bucket: String,
4244
amount: Int,
4345
) {
@@ -61,7 +63,7 @@ class SyncProgressTest : BaseInMemorySyncTest() {
6163
)
6264
}
6365

64-
private suspend fun addCheckpointComplete(priority: BucketPriority? = null) {
66+
private suspend fun ActiveDatabaseTest.addCheckpointComplete(priority: BucketPriority? = null) {
6567
if (priority != null) {
6668
syncLines.send(
6769
SyncLine.CheckpointPartiallyComplete(
@@ -102,9 +104,8 @@ class SyncProgressTest : BaseInMemorySyncTest() {
102104

103105
@Test
104106
fun withoutPriorities() =
105-
runTest {
106-
val syncStream = syncStream()
107-
database.connectInternal(syncStream, 1000L)
107+
databaseTest {
108+
database.connect(connector)
108109

109110
turbineScope {
110111
val turbine = database.currentStatus.asFlow().testIn(this)
@@ -152,9 +153,8 @@ class SyncProgressTest : BaseInMemorySyncTest() {
152153

153154
@Test
154155
fun interruptedSync() =
155-
runTest {
156-
var syncStream = syncStream()
157-
database.connectInternal(syncStream, 1000L)
156+
databaseTest {
157+
database.connect(connector)
158158

159159
turbineScope {
160160
val turbine = database.currentStatus.asFlow().testIn(this)
@@ -182,10 +182,9 @@ class SyncProgressTest : BaseInMemorySyncTest() {
182182
syncLines.close()
183183

184184
// And reconnecting
185-
database = openDb()
185+
database = openDatabase()
186186
syncLines = Channel()
187-
syncStream = syncStream()
188-
database.connectInternal(syncStream, 1000L)
187+
database.connect(connector)
189188

190189
turbineScope {
191190
val turbine = database.currentStatus.asFlow().testIn(this)
@@ -218,9 +217,8 @@ class SyncProgressTest : BaseInMemorySyncTest() {
218217

219218
@Test
220219
fun interruptedSyncWithNewCheckpoint() =
221-
runTest {
222-
var syncStream = syncStream()
223-
database.connectInternal(syncStream, 1000L)
220+
databaseTest {
221+
database.connect(connector)
224222

225223
turbineScope {
226224
val turbine = database.currentStatus.asFlow().testIn(this)
@@ -244,10 +242,9 @@ class SyncProgressTest : BaseInMemorySyncTest() {
244242
// Close and re-connect
245243
database.close()
246244
syncLines.close()
247-
database = openDb()
245+
database = openDatabase()
248246
syncLines = Channel()
249-
syncStream = syncStream()
250-
database.connectInternal(syncStream, 1000L)
247+
database.connect(connector)
251248

252249
turbineScope {
253250
val turbine = database.currentStatus.asFlow().testIn(this)
@@ -279,9 +276,8 @@ class SyncProgressTest : BaseInMemorySyncTest() {
279276

280277
@Test
281278
fun differentPriorities() =
282-
runTest {
283-
val syncStream = syncStream()
284-
database.connectInternal(syncStream, 1000L)
279+
databaseTest {
280+
database.connect(connector)
285281

286282
turbineScope {
287283
val turbine = database.currentStatus.asFlow().testIn(this)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ internal class ActiveDatabaseTest(
8282
),
8383
)
8484

85-
val syncLines = Channel<SyncLine>()
85+
var syncLines = Channel<SyncLine>()
8686
var checkpointResponse: () -> WriteCheckpointResponse = {
8787
WriteCheckpointResponse(WriteCheckpointData("1000"))
8888
}

0 commit comments

Comments
 (0)