Fix engine start/stop for integration tests
This commit is contained in:
@@ -14,6 +14,8 @@ import io.ktor.util.KtorExperimentalAPI
|
|||||||
import io.lettuce.core.RedisClient
|
import io.lettuce.core.RedisClient
|
||||||
import io.lettuce.core.api.sync.RedisCommands
|
import io.lettuce.core.api.sync.RedisCommands
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
|
import org.junit.jupiter.api.AfterAll
|
||||||
import org.junit.jupiter.api.AfterEach
|
import org.junit.jupiter.api.AfterEach
|
||||||
import org.junit.jupiter.api.BeforeAll
|
import org.junit.jupiter.api.BeforeAll
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
@@ -32,9 +34,10 @@ abstract class BaseTest : KoinTest {
|
|||||||
.apply { setUri(config.rabbitmq) }
|
.apply { setUri(config.rabbitmq) }
|
||||||
.newConnection()
|
.newConnection()
|
||||||
.createChannel()
|
.createChannel()
|
||||||
private val engine = TestApplicationEngine(createTestEnvironment())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val engine = TestApplicationEngine(createTestEnvironment())
|
||||||
|
|
||||||
protected fun <R> withIntegrationApplication(
|
protected fun <R> withIntegrationApplication(
|
||||||
test: TestApplicationEngine.() -> R
|
test: TestApplicationEngine.() -> R
|
||||||
): R {
|
): R {
|
||||||
@@ -43,17 +46,24 @@ abstract class BaseTest : KoinTest {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
fun before() {
|
fun before() {
|
||||||
|
engine.start()
|
||||||
|
engine.application.module(TEST)
|
||||||
if (init == false) {
|
if (init == false) {
|
||||||
engine.start()
|
|
||||||
engine.application.module(TEST)
|
|
||||||
init = true
|
init = true
|
||||||
get<Migrations>().run {
|
get<Migrations>().run {
|
||||||
forceAllDown()
|
forceAllDown()
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
get<Connection>()
|
|
||||||
.sendQuery("start transaction;", listOf())
|
|
||||||
}
|
}
|
||||||
|
get<Connection>()
|
||||||
|
.sendQuery("start transaction;", listOf())
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
fun after() {
|
||||||
|
get<Connection>()
|
||||||
|
.sendQuery("rollback;", listOf())
|
||||||
|
engine.stop(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package integration.citizen
|
package integration
|
||||||
|
|
||||||
import integration.BaseTest
|
import integration.BaseTest
|
||||||
import integration.asserts.`And have property`
|
import integration.asserts.`And have property`
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package integration.auth
|
package integration
|
||||||
|
|
||||||
import integration.BaseTest
|
import integration.BaseTest
|
||||||
import integration.asserts.`And the response should not be null`
|
import integration.asserts.`And the response should not be null`
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package integration.auth
|
package integration
|
||||||
|
|
||||||
import integration.BaseTest
|
|
||||||
import integration.asserts.`Then the response should be`
|
import integration.asserts.`Then the response should be`
|
||||||
import integration.asserts.`when`.`When I send a POST request`
|
import integration.asserts.`when`.`When I send a POST request`
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
Reference in New Issue
Block a user