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.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() {
if (init == false) {
engine.start() engine.start()
engine.application.module(TEST) engine.application.module(TEST)
if (init == false) {
init = true init = true
get<Migrations>().run { get<Migrations>().run {
forceAllDown() forceAllDown()
run() run()
} }
}
get<Connection>() get<Connection>()
.sendQuery("start transaction;", listOf()) .sendQuery("start transaction;", listOf())
} }
@AfterAll
fun after() {
get<Connection>()
.sendQuery("rollback;", listOf())
engine.stop(0, 0)
} }
@BeforeEach @BeforeEach

View File

@@ -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`

View File

@@ -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`

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.`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