Skip to content

Commit

Permalink
refactor: Add query timeout test code
Browse files Browse the repository at this point in the history
  • Loading branch information
FullOfOrange committed Nov 23, 2023
1 parent c7d15a8 commit c493e1b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,4 @@ class MysqlTests : DatabaseTestsBase() {
}
}
}

@Test
fun timeoutStatements() {
withDb(listOf(TestDB.MYSQL)) {
this.timeout = 3
assertFailsWith<ExposedSQLException> {
TransactionManager.current().exec(
"SELECT SLEEP(5) = 0;"
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,6 @@ class PostgresqlTests : DatabaseTestsBase() {
}
}

@Test
fun timeoutStatements() {
withDb(listOf(TestDB.POSTGRESQL)) {
this.timeout = 3
assertFailsWith<ExposedSQLException> {
TransactionManager.current().exec(
"SELECT 1 WHERE pg_sleep(5);"
)
}
}
}

private fun Transaction.withTable(statement: Transaction.() -> Unit) {
SchemaUtils.create(table)
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jetbrains.exposed.sql.tests.shared

import org.jetbrains.exposed.exceptions.ExposedSQLException
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase
import org.jetbrains.exposed.sql.tests.TestDB
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.junit.Test
import kotlin.test.assertFailsWith

/**
* @author [email protected]
*/
class QueryTimeoutTest : DatabaseTestsBase() {

private fun generateTimeoutStatements(db: TestDB, timeout: Int): String {
return when (db) {
TestDB.MYSQL -> "SELECT SLEEP($timeout) = 0;"
TestDB.POSTGRESQL -> "SELECT pg_sleep($timeout);"
else -> throw NotImplementedError()
}
}

@Test
fun timeoutStatements() {
withDb(listOf(TestDB.MYSQL, TestDB.POSTGRESQL)) {
this.timeout = 3
assertFailsWith<ExposedSQLException> {
TransactionManager.current().exec(
generateTimeoutStatements(it, 5)
)
}
}
}

@Test
fun noTimeoutWithTimeoutStatement() {
withDb(listOf(TestDB.MYSQL, TestDB.POSTGRESQL)) {
this.timeout = 3
TransactionManager.current().exec(
generateTimeoutStatements(it, 1)
)
}
}
}

0 comments on commit c493e1b

Please sign in to comment.