Skip to content

Commit

Permalink
isolate enabling of the extension and surround with runCatching
Browse files Browse the repository at this point in the history
  • Loading branch information
jillesvangurp committed Jan 5, 2024
1 parent ba58e0e commit 65e2dd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/main/kotlin/com/tryformation/pgdocstore/schema-support.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ suspend fun SuspendingConnection.dropDocStoreTable(tableName: String = "docstore

suspend fun SuspendingConnection.createDocStoreTable(tableName: String) {
inTransaction { c ->
runCatching {
// this sometimes fails in CI and we don't care
// we have lots of tests running concurrently so this can happen
// somehow
c.sendQuery(
"CREATE EXTENSION IF NOT EXISTS pg_trgm;"
)
}
c.sendQuery(
"""
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE TABLE IF NOT EXISTS "$tableName" (
id text PRIMARY KEY,
created_at timestamptz DEFAULT current_timestamp,
Expand Down
7 changes: 6 additions & 1 deletion src/test/kotlin/com/tryformation/pgdocstore/DbTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ open class DbTestBase {
tableName = "docs_${Random.nextULong()}"
db.createDocStoreTable(tableName)
}


@AfterAll
fun afterAll() = coRun {
db.dropDocStoreTable(tableName)
}

fun coRun(timeout: Duration = 1.minutes, block: suspend () -> Unit) {
runBlocking {
withTimeout(timeout) {
Expand Down

0 comments on commit 65e2dd3

Please sign in to comment.