Skip to content

Commit

Permalink
chore: pipeline freeze during tests (#2553)
Browse files Browse the repository at this point in the history
Fixes  #2551
  • Loading branch information
Anty0 authored Oct 10, 2024
1 parent c1b0d4d commit 39ad980
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
timeout_minutes: 30
max_attempts: ${{ github.event_name == 'push' && 5 || 1 }}
# Print free memory for debugging purposes
command: free -h && ./gradlew ${{ matrix.command }}
command: ./gradlew ${{ matrix.command }}
env:
SKIP_SERVER_BUILD: true
CI_RELEASE: ${{ github.event_name == 'push' && true || false }}
Expand Down
3 changes: 3 additions & 0 deletions backend/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ test {
}

tasks.register('runContextRecreatingTests', Test) {
outputs.upToDateWhen { false }
useJUnitPlatform {
includeTags "contextRecreating"
}
Expand All @@ -214,6 +215,7 @@ tasks.register('runContextRecreatingTests', Test) {
}

tasks.register('runStandardTests', Test) {
outputs.upToDateWhen { false }
useJUnitPlatform {
excludeTags "contextRecreating", "websocket"
}
Expand All @@ -222,6 +224,7 @@ tasks.register('runStandardTests', Test) {
}

tasks.register('runWebsocketTests', Test) {
outputs.upToDateWhen { false }
useJUnitPlatform {
includeTags "websocket"
}
Expand Down
56 changes: 32 additions & 24 deletions backend/testing/src/main/kotlin/io/tolgee/CleanDbTestListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ class CleanDbTestListener : TestExecutionListener {
)

override fun beforeTestMethod(testContext: TestContext) {
val appContext: ApplicationContext = testContext.applicationContext
val batchJobConcurrentLauncher = appContext.getBean(BatchJobConcurrentLauncher::class.java)
val batchJobQueue = appContext.getBean(BatchJobChunkExecutionQueue::class.java)

if (!shouldClenBeforeClass(testContext)) {
batchJobConcurrentLauncher.pause = true
batchJobQueue.clear()
cleanWithRetries(testContext)
batchJobConcurrentLauncher.pause = false
}
}

private fun cleanWithRetries(testContext: TestContext) {
logger.info("Cleaning DB")

val appContext: ApplicationContext = testContext.applicationContext
val batchJobConcurrentLauncher = appContext.getBean(BatchJobConcurrentLauncher::class.java)
val batchJobQueue = appContext.getBean(BatchJobChunkExecutionQueue::class.java)

batchJobConcurrentLauncher.pause = true
batchJobQueue.clear()

val time =
measureTimeMillis {
var i = 0
Expand All @@ -62,6 +63,8 @@ class CleanDbTestListener : TestExecutionListener {
}
}
}

batchJobConcurrentLauncher.pause = false
logger.info("DB cleaned in ${time}ms")
}

Expand All @@ -72,26 +75,31 @@ class CleanDbTestListener : TestExecutionListener {
val stmt = conn.createStatement()
val databaseName: Any = "postgres"
val ignoredTablesString = ignoredTables.joinToString(", ") { "'$it'" }
val rs: ResultSet =
stmt.executeQuery(
String.format(
"SELECT table_schema, table_name" +
" FROM information_schema.tables" +
" WHERE table_catalog = '%s' and (table_schema in ('public', 'billing', 'ee'))" +
" and table_name not in ($ignoredTablesString)",
databaseName,
try {
val rs: ResultSet =
stmt.executeQuery(
String.format(
"SELECT table_schema, table_name" +
" FROM information_schema.tables" +
" WHERE table_catalog = '%s' and (table_schema in ('public', 'billing', 'ee'))" +
" and table_name not in ($ignoredTablesString)",
databaseName,
),
)
val tables: MutableList<Pair<String, String>> = ArrayList()
while (rs.next()) {
tables.add(rs.getString(1) to rs.getString(2))
}
stmt.execute(
java.lang.String.format(
"TRUNCATE TABLE %s",
tables.joinToString(",") { it.first + "." + it.second },
),
)
val tables: MutableList<Pair<String, String>> = ArrayList()
while (rs.next()) {
tables.add(rs.getString(1) to rs.getString(2))
} catch (e: InterruptedException) {
stmt.cancel()
throw e
}
stmt.execute(
java.lang.String.format(
"TRUNCATE TABLE %s",
tables.joinToString(",") { it.first + "." + it.second },
),
)
}
}

Expand Down

0 comments on commit 39ad980

Please sign in to comment.