Skip to content

Commit b7e43c4

Browse files
committed
Avoid using allprojects and subprojects
1 parent 8682730 commit b7e43c4

File tree

10 files changed

+273
-255
lines changed

10 files changed

+273
-255
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
include:
2323
- os: macos-latest
2424
name: watchos
25-
targets: watchosSimulatorArm64Test tvosSimulatorArm64Test
25+
targets: watchosSimulatorArm64Test
2626
- os: macos-latest
2727
name: tvos
2828
targets: tvosSimulatorArm64Test

build.gradle.kts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ plugins {
1616
alias(libs.plugins.mavenPublishPlugin) apply false
1717
alias(libs.plugins.downloadPlugin) apply false
1818
alias(libs.plugins.kotlinter) apply false
19-
alias(libs.plugins.keeper) apply false
2019
alias(libs.plugins.kotlin.atomicfu) apply false
2120
alias(libs.plugins.cocoapods) apply false
2221
alias(libs.plugins.ksp) apply false
@@ -25,42 +24,6 @@ plugins {
2524
id("dokka-convention")
2625
}
2726

28-
allprojects {
29-
repositories {
30-
mavenCentral()
31-
google()
32-
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
33-
maven("https://www.jetbrains.com/intellij-repository/releases")
34-
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
35-
// Repo for the backported Android IntelliJ Plugin by Jetbrains used in Ultimate
36-
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies/")
37-
}
38-
39-
configurations.configureEach {
40-
exclude(group = "com.jetbrains.rd")
41-
exclude(group = "com.github.jetbrains", module = "jetCheck")
42-
exclude(group = "com.jetbrains.intellij.platform", module = "wsl-impl")
43-
exclude(group = "org.roaringbitmap")
44-
exclude(group = "com.jetbrains.infra")
45-
exclude(group = "org.jetbrains.teamcity")
46-
exclude(group = "org.roaringbitmap")
47-
exclude(group = "ai.grazie.spell")
48-
exclude(group = "ai.grazie.model")
49-
exclude(group = "ai.grazie.utils")
50-
exclude(group = "ai.grazie.nlp")
51-
52-
// We have a transitive dependency on this due to Kermit, but need the fixed version to support Java 8
53-
resolutionStrategy.force("co.touchlab:stately-collections:${libs.versions.stately.get()}")
54-
}
55-
}
56-
subprojects {
57-
val GROUP: String by project
58-
val LIBRARY_VERSION: String by project
59-
60-
group = GROUP
61-
version = LIBRARY_VERSION
62-
}
63-
6427
tasks.getByName<Delete>("clean") {
6528
delete(rootProject.layout.buildDirectory)
6629
}

core-tests-android/build.gradle.kts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
import com.slack.keeper.optInToKeeper
2-
31
plugins {
42
alias(libs.plugins.android.application)
53
alias(libs.plugins.kotlin.android)
6-
alias(libs.plugins.keeper)
74
}
85

96
dependencies {
107
implementation(projects.core)
118
implementation(libs.androidx.core)
129
implementation(libs.androidx.appcompat)
1310
implementation(libs.androidx.material)
11+
implementation(libs.test.coroutines)
12+
implementation(libs.test.turbine)
1413

1514
androidTestImplementation(libs.androidx.junit)
1615
androidTestImplementation(libs.androidx.espresso.core)
17-
androidTestImplementation(libs.test.coroutines)
18-
androidTestImplementation(libs.test.turbine)
1916
}
2017

2118
android {
@@ -35,7 +32,10 @@ android {
3532
buildTypes {
3633
release {
3734
isMinifyEnabled = true
38-
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
35+
proguardFiles(
36+
getDefaultProguardFile("proguard-android-optimize.txt"),
37+
"proguard-rules.pro"
38+
)
3939
signingConfig = signingConfigs.getByName("debug")
4040
}
4141
}
@@ -48,7 +48,3 @@ android {
4848
jvmTarget = "11"
4949
}
5050
}
51-
52-
androidComponents {
53-
beforeVariants { it.optInToKeeper() }
54-
}

core-tests-android/proguard-rules.pro

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,20 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile
22+
23+
# This is the entrypoint in the app, we want to minify everything else to simulate a real app build.
24+
-keep class com.powersync.testutils.IntegrationTestHelpers {
25+
*;
26+
}
27+
28+
# Not used in main app, needed for testing
29+
-keep class kotlin.** {
30+
*;
31+
}
32+
33+
-keep class androidx.tracing.Trace {
34+
public static void beginSection(java.lang.String);
35+
public static void endSection();
36+
public static void forceEnableAppTracing();
37+
}
Lines changed: 13 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -1,235 +1,47 @@
11
package com.powersync
22

3+
import com.powersync.testutils.IntegrationTestHelpers
34
import androidx.test.ext.junit.runners.AndroidJUnit4
45
import androidx.test.platform.app.InstrumentationRegistry
5-
import app.cash.turbine.turbineScope
6-
import com.powersync.db.schema.Schema
7-
import com.powersync.testutils.UserRow
8-
import kotlinx.coroutines.*
9-
import kotlinx.coroutines.runBlocking
10-
import kotlinx.coroutines.test.runTest
116
import org.junit.After
12-
import org.junit.Assert.*
137
import org.junit.Before
148
import org.junit.Test
159
import org.junit.runner.RunWith
1610

1711
@RunWith(AndroidJUnit4::class)
1812
class AndroidDatabaseTest {
19-
private lateinit var database: PowerSyncDatabase
13+
private val helpers = IntegrationTestHelpers(
14+
InstrumentationRegistry.getInstrumentation().targetContext
15+
)
2016

2117
@Before
2218
fun setupDatabase() {
23-
database =
24-
PowerSyncDatabase(
25-
factory = DatabaseDriverFactory(InstrumentationRegistry.getInstrumentation().targetContext),
26-
schema = Schema(UserRow.table),
27-
dbFilename = "testdb",
28-
)
29-
30-
runBlocking {
31-
database.disconnectAndClear(true)
32-
}
19+
helpers.setup()
3320
}
3421

3522
@After
3623
fun tearDown() {
37-
runBlocking {
38-
database.disconnectAndClear(true)
39-
database.close()
40-
}
24+
helpers.tearDown()
4125
}
4226

4327
@Test
44-
fun testLinksPowerSync() =
45-
runTest {
46-
database.get("SELECT powersync_rs_version() AS r;") { it.getString(0)!! }
47-
}
28+
fun testLinksPowerSync() = helpers.testLinksPowerSync()
4829

4930
@Test
50-
fun testTableUpdates() =
51-
runTest {
52-
turbineScope {
53-
val query = database.watch("SELECT * FROM users") { UserRow.from(it) }.testIn(this)
54-
55-
// Wait for initial query
56-
assertEquals(0, query.awaitItem().size)
57-
58-
database.execute(
59-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
60-
listOf("Test", "[email protected]"),
61-
)
62-
assertEquals(1, query.awaitItem().size)
63-
64-
database.writeTransaction {
65-
it.execute(
66-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
67-
listOf("Test2", "[email protected]"),
68-
)
69-
it.execute(
70-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
71-
listOf("Test3", "[email protected]"),
72-
)
73-
}
74-
75-
assertEquals(3, query.awaitItem().size)
76-
77-
try {
78-
database.writeTransaction {
79-
it.execute("DELETE FROM users;")
80-
it.execute("syntax error, revert please")
81-
}
82-
} catch (e: Exception) {
83-
// Ignore
84-
}
85-
86-
database.execute(
87-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
88-
listOf("Test4", "[email protected]"),
89-
)
90-
assertEquals(4, query.awaitItem().size)
91-
92-
query.expectNoEvents()
93-
query.cancel()
94-
}
95-
}
31+
fun testTableUpdates() = helpers.testTableUpdates()
9632

9733
@Test
98-
fun testConcurrentReads() =
99-
runTest {
100-
database.execute(
101-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
102-
listOf(
103-
"steven",
104-
105-
),
106-
)
107-
108-
val pausedTransaction = CompletableDeferred<Unit>()
109-
val transactionItemCreated = CompletableDeferred<Unit>()
110-
// Start a long running writeTransaction
111-
val transactionJob =
112-
async {
113-
database.writeTransaction { tx ->
114-
// Create another user
115-
// External readers should not see this user while the transaction is open
116-
tx.execute(
117-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
118-
listOf(
119-
"steven",
120-
121-
),
122-
)
123-
124-
transactionItemCreated.complete(Unit)
125-
126-
// Block this transaction until we free it
127-
runBlocking {
128-
pausedTransaction.await()
129-
}
130-
}
131-
}
132-
133-
// Make sure to wait for the item to have been created in the transaction
134-
transactionItemCreated.await()
135-
// Try and read while the write transaction is busy
136-
val result = database.getAll("SELECT * FROM users") { UserRow.from(it) }
137-
// The transaction is not commited yet, we should only read 1 user
138-
assertEquals(result.size, 1)
139-
140-
// Let the transaction complete
141-
pausedTransaction.complete(Unit)
142-
transactionJob.await()
143-
144-
val afterTx = database.getAll("SELECT * FROM users") { UserRow.from(it) }
145-
assertEquals(afterTx.size, 2)
146-
}
34+
fun testConcurrentReads() = helpers.testConcurrentReads()
14735

14836
@Test
149-
fun transactionReads() =
150-
runTest {
151-
database.execute(
152-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
153-
listOf(
154-
"steven",
155-
156-
),
157-
)
158-
159-
database.writeTransaction { tx ->
160-
val userCount =
161-
tx.getAll("SELECT COUNT(*) as count FROM users") { cursor -> cursor.getLong(0)!! }
162-
assertEquals(userCount[0], 1)
163-
164-
tx.execute(
165-
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
166-
listOf(
167-
"steven",
168-
169-
),
170-
)
171-
172-
// Getters inside the transaction should be able to see the latest update
173-
val userCount2 =
174-
tx.getAll("SELECT COUNT(*) as count FROM users") { cursor -> cursor.getLong(0)!! }
175-
assertEquals(userCount2[0], 2)
176-
}
177-
}
37+
fun transactionReads() = helpers.transactionReads()
17838

17939
@Test
180-
fun openDBWithDirectory() =
181-
runTest {
182-
val tempDir =
183-
InstrumentationRegistry
184-
.getInstrumentation()
185-
.targetContext.cacheDir.canonicalPath
186-
val dbFilename = "testdb"
187-
188-
val db =
189-
PowerSyncDatabase(
190-
factory = DatabaseDriverFactory(InstrumentationRegistry.getInstrumentation().targetContext),
191-
schema = Schema(UserRow.table),
192-
dbDirectory = tempDir,
193-
dbFilename = dbFilename,
194-
)
195-
196-
val path = db.get("SELECT file FROM pragma_database_list;") { it.getString(0)!! }
197-
198-
assertEquals(path.contains(tempDir), true)
199-
200-
db.close()
201-
}
40+
fun openDBWithDirectory() = helpers.openDBWithDirectory()
20241

20342
@Test
204-
fun readConnectionsReadOnly() =
205-
runTest {
206-
val exception =
207-
assertThrows(PowerSyncException::class.java) {
208-
// This version of assertThrows does not support suspending functions
209-
runBlocking {
210-
database.getOptional(
211-
"""
212-
INSERT INTO
213-
users (id, name, email)
214-
VALUES
215-
(uuid(), ?, ?)
216-
RETURNING *
217-
""".trimIndent(),
218-
parameters = listOf("steven", "[email protected]"),
219-
) {}
220-
}
221-
}
222-
// The exception messages differ slightly between drivers
223-
assertEquals(exception.message!!.contains("write a readonly database"), true)
224-
}
43+
fun readConnectionsReadOnly() = helpers.readConnectionsReadOnly()
22544

22645
@Test
227-
fun canUseTempStore() = runTest {
228-
database.execute("PRAGMA temp_store = 1;") // Store temporary data as files
229-
database.execute("CREATE TEMP TABLE foo (bar TEXT);")
230-
val data = "new row".repeat(100);
231-
for (i in 0..10000) {
232-
database.execute("INSERT INTO foo VALUES (?)", parameters = listOf(data))
233-
}
234-
}
46+
fun canUseTempStore() = helpers.canUseTempStore()
23547
}

0 commit comments

Comments
 (0)