Fix engine start/stop for integration tests

This commit is contained in:
2021-02-10 01:08:23 +01:00
parent ec0115d613
commit 99438b1ff9
4 changed files with 18 additions and 9 deletions

View File

@@ -14,6 +14,8 @@ import io.ktor.util.KtorExperimentalAPI
import io.lettuce.core.RedisClient
import io.lettuce.core.api.sync.RedisCommands
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.BeforeAll
import org.junit.jupiter.api.BeforeEach
@@ -32,9 +34,10 @@ abstract class BaseTest : KoinTest {
.apply { setUri(config.rabbitmq) }
.newConnection()
.createChannel()
private val engine = TestApplicationEngine(createTestEnvironment())
}
private val engine = TestApplicationEngine(createTestEnvironment())
protected fun <R> withIntegrationApplication(
test: TestApplicationEngine.() -> R
): R {
@@ -43,17 +46,24 @@ abstract class BaseTest : KoinTest {
@BeforeAll
fun before() {
if (init == false) {
engine.start()
engine.application.module(TEST)
if (init == false) {
init = true
get<Migrations>().run {
forceAllDown()
run()
}
}
get<Connection>()
.sendQuery("start transaction;", listOf())
}
@AfterAll
fun after() {
get<Connection>()
.sendQuery("rollback;", listOf())
engine.stop(0, 0)
}
@BeforeEach

View File

@@ -1,4 +1,4 @@
package integration.citizen
package integration
import integration.BaseTest
import integration.asserts.`And have property`

View File

@@ -1,4 +1,4 @@
package integration.auth
package integration
import integration.BaseTest
import integration.asserts.`And the response should not be null`

View File

@@ -1,6 +1,5 @@
package integration.auth
package integration
import integration.BaseTest
import integration.asserts.`Then the response should be`
import integration.asserts.`when`.`When I send a POST request`
import io.ktor.http.HttpStatusCode