Skip to content

Commit 0089ccb

Browse files
committed
Fix Android release tests
1 parent be279f6 commit 0089ccb

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

core-tests-android/src/androidTest/java/com/powersync/AndroidDatabaseTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class AndroidDatabaseTest {
3434

3535
@After
3636
fun tearDown() {
37-
runBlocking { database.disconnectAndClear(true) }
37+
runBlocking {
38+
database.disconnectAndClear(true)
39+
database.close()
40+
}
3841
}
3942

4043
@Test

core/src/commonMain/kotlin/com/powersync/db/ActiveInstanceStore.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.powersync.db
22

33
import co.touchlab.kermit.Logger
4-
import kotlinx.atomicfu.atomic
5-
import kotlinx.atomicfu.locks.SynchronizedObject
6-
import kotlinx.atomicfu.locks.synchronized
4+
import co.touchlab.stately.concurrency.AtomicBoolean
5+
import co.touchlab.stately.concurrency.Synchronizable
6+
import co.touchlab.stately.concurrency.synchronize
77
import kotlinx.coroutines.sync.Mutex
88

99
/**
@@ -27,14 +27,14 @@ internal class ActiveDatabaseGroup(
2727
internal val syncMutex = Mutex()
2828

2929
fun removeUsage() {
30-
synchronized(ActiveDatabaseGroup) {
30+
ActiveDatabaseGroup.synchronize {
3131
if (--refCount == 0) {
3232
allGroups.remove(this)
3333
}
3434
}
3535
}
3636

37-
companion object : SynchronizedObject() {
37+
companion object : Synchronizable() {
3838
internal val multipleInstancesMessage =
3939
"""
4040
Multiple PowerSync instances for the same database have been detected.
@@ -47,8 +47,7 @@ internal class ActiveDatabaseGroup(
4747
private fun findGroup(
4848
warnOnDuplicate: Logger,
4949
identifier: String,
50-
): ActiveDatabaseGroup =
51-
synchronized(this) {
50+
): ActiveDatabaseGroup = synchronize {
5251
val existing = allGroups.asSequence().firstOrNull { it.identifier == identifier }
5352
val resolvedGroup =
5453
if (existing == null) {
@@ -81,10 +80,10 @@ internal class ActiveDatabaseGroup(
8180
internal class ActiveDatabaseResource(
8281
val group: ActiveDatabaseGroup,
8382
) {
84-
val disposed = atomic(false)
83+
val disposed = AtomicBoolean(false)
8584

8685
fun dispose() {
87-
if (!disposed.getAndSet(true)) {
86+
if (disposed.compareAndSet(false, true)) {
8887
group.removeUsage()
8988
}
9089
}

0 commit comments

Comments
 (0)