-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add query timeout test code
- Loading branch information
1 parent
c7d15a8
commit c493e1b
Showing
3 changed files
with
44 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/QueryTimeoutTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} | ||
} |