Skip to content

Commit 7f34c8a

Browse files
committed
fix(backend): ExportServiceTest SQLite - single connection for in-memory, busy_timeout on verify
- Database.initForTests: use pool size 1 and minimumIdle 0 for :memory: SQLite so export (on IO dispatcher) sees the same DB as test - ExportServiceTest: add busy_timeout=5000 when opening exported file for verify; use requireNotNull for exported flag row Made-with: Cursor
1 parent 01d0f49 commit 7f34c8a

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

backend/src/main/kotlin/flagent/repository/Database.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ object Database {
4444
*/
4545
fun initForTests(jdbcUrl: String, driverClassName: String = "org.postgresql.Driver") {
4646
close()
47+
val isInMemorySqlite = jdbcUrl.contains(":memory:", ignoreCase = true)
4748
val config = HikariConfig().apply {
4849
this.driverClassName = driverClassName
4950
this.jdbcUrl = jdbcUrl
50-
maximumPoolSize = 2
51-
minimumIdle = 1
51+
// SQLite :memory: is per-connection; pool size 1 so all code sees the same DB
52+
maximumPoolSize = if (isInMemorySqlite) 1 else 2
53+
minimumIdle = if (isInMemorySqlite) 0 else 1
5254
connectionTimeout = 30000
5355
}
5456
dataSource = HikariDataSource(config)

backend/src/test/kotlin/flagent/service/ExportServiceTest.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,19 @@ class ExportServiceTest {
6464
// Assert: Verify SQLite file is created and contains data
6565
assertTrue(sqliteBytes.isNotEmpty(), "SQLite export should return non-empty bytes")
6666

67-
// Verify by reading the SQLite file
67+
// Verify by reading the SQLite file (busy_timeout for CI where SQLite can be briefly locked)
6868
val tempFile = File.createTempFile("test_export_", ".sqlite")
6969
try {
7070
tempFile.writeBytes(sqliteBytes)
71-
71+
val url = "jdbc:sqlite:${tempFile.absolutePath}?busy_timeout=5000"
7272
val db = org.jetbrains.exposed.v1.jdbc.Database.connect(
73-
url = "jdbc:sqlite:${tempFile.absolutePath}",
73+
url = url,
7474
driver = "org.sqlite.JDBC"
7575
)
76-
7776
transaction(db) {
7877
val flagCount = Flags.selectAll().count()
7978
assertEquals(1, flagCount, "Should export 1 flag")
80-
81-
val exportedFlag = Flags.selectAll().where { Flags.id eq createdFlag.id }.firstOrNull()
82-
assertNotNull(exportedFlag, "Exported flag should exist")
79+
val exportedFlag = requireNotNull(Flags.selectAll().where { Flags.id eq createdFlag.id }.firstOrNull()) { "Exported flag should exist" }
8380
assertEquals(createdFlag.key, exportedFlag[Flags.key], "Flag key should match")
8481
assertEquals(createdFlag.description, exportedFlag[Flags.description], "Flag description should match")
8582
}

0 commit comments

Comments
 (0)