test: 結合テストが壊れていたので修正

This commit is contained in:
usbharu 2024-05-12 01:46:32 +09:00
parent 6a4921cfac
commit 5f534d83e9
22 changed files with 108 additions and 22 deletions

View File

@ -18,6 +18,8 @@ package activitypub.inbox
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.util.Base64Util
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach
@ -150,9 +152,12 @@ class InboxTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -17,6 +17,8 @@
package activitypub.note
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach
@ -230,9 +232,12 @@ class NoteTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -18,6 +18,8 @@ package activitypub.webfinger
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.application.external.Transaction
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Test
@ -103,9 +105,12 @@ class WebFingerTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -20,6 +20,8 @@ import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
@ -152,9 +154,13 @@ class AccountApiPaginationTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -19,6 +19,8 @@ package mastodon.account
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.infrastructure.exposedquery.FollowerQueryServiceImpl
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.flywaydb.core.Flyway
@ -462,9 +464,12 @@ class AccountApiTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -18,6 +18,8 @@ package mastodon.apps
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.RegisteredClient
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.flywaydb.core.Flyway
import org.jetbrains.exposed.sql.selectAll
@ -107,9 +109,12 @@ class AppTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -22,6 +22,8 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.FilterKeywordsPostReq
import dev.usbharu.hideout.domain.mastodon.model.generated.FilterPostRequest
import dev.usbharu.hideout.domain.mastodon.model.generated.FilterPostRequestKeyword
import dev.usbharu.hideout.domain.mastodon.model.generated.V1FilterPostRequest
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
@ -702,9 +704,12 @@ class FilterTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -20,6 +20,8 @@ import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.core.service.media.MediaDataStore
import dev.usbharu.hideout.core.service.media.MediaSaveRequest
import dev.usbharu.hideout.core.service.media.SuccessSavedMedia
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
@ -131,9 +133,12 @@ class MediaTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}

View File

@ -20,6 +20,8 @@ import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.domain.mastodon.model.generated.Notification
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.flywaydb.core.Flyway
@ -172,9 +174,12 @@ class ExposedNotificationsApiPaginationTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -23,6 +23,8 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Notification
import dev.usbharu.hideout.mastodon.domain.model.MastodonNotification
import dev.usbharu.hideout.mastodon.domain.model.NotificationType
import dev.usbharu.hideout.mastodon.infrastructure.mongorepository.MongoMastodonNotificationRepository
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions
import org.flywaydb.core.Flyway
@ -178,7 +180,7 @@ class MongodbNotificationsApiPaginationTest {
@JvmStatic
@BeforeAll
fun setupMongodb(
@Autowired mongoMastodonNotificationRepository: MongoMastodonNotificationRepository
@Autowired mongoMastodonNotificationRepository: MongoMastodonNotificationRepository,
) {
mongoMastodonNotificationRepository.deleteAll()
@ -203,11 +205,14 @@ class MongodbNotificationsApiPaginationTest {
@AfterAll
fun dropDatabase(
@Autowired flyway: Flyway,
@Autowired mongodbMastodonNotificationRepository: MongoMastodonNotificationRepository
@Autowired mongodbMastodonNotificationRepository: MongoMastodonNotificationRepository,
@Autowired owlProducer: OwlProducer,
) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
mongodbMastodonNotificationRepository.deleteAll()
}
}

View File

@ -22,6 +22,8 @@ import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji
import dev.usbharu.hideout.core.infrastructure.exposedrepository.CustomEmojis
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Reactions
import dev.usbharu.hideout.core.infrastructure.exposedrepository.toReaction
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.flywaydb.core.Flyway
import org.jetbrains.exposed.sql.and
@ -236,9 +238,12 @@ class StatusTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -17,6 +17,8 @@
package mastodon.timelines
import dev.usbharu.hideout.SpringApplication
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach
@ -123,9 +125,12 @@ class TimelineApiTest {
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
fun dropDatabase(@Autowired flyway: Flyway, @Autowired owlProducer: OwlProducer) {
flyway.clean()
flyway.migrate()
runBlocking {
owlProducer.stop()
}
}
}
}

View File

@ -19,17 +19,25 @@ package dev.usbharu.hideout.application.external
import dev.usbharu.owl.common.task.TaskDefinition
import dev.usbharu.owl.producer.api.OwlProducer
import kotlinx.coroutines.runBlocking
import org.springframework.beans.factory.DisposableBean
import org.springframework.boot.ApplicationArguments
import org.springframework.boot.ApplicationRunner
import org.springframework.stereotype.Component
@Component
class OwlProducerRunner(private val owlProducer: OwlProducer, private val taskDefinitions: List<TaskDefinition<*>>) :
ApplicationRunner {
ApplicationRunner, DisposableBean {
override fun run(args: ApplicationArguments?) {
runBlocking {
owlProducer.start()
taskDefinitions.forEach { taskDefinition -> owlProducer.registerTask(taskDefinition) }
}
}
override fun destroy() {
System.err.println("destroy aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
runBlocking {
owlProducer.stop()
}
}
}

View File

@ -31,5 +31,4 @@ data class DeliverCreateTask(
data object DeliverCreateTaskDef : TaskDefinition<DeliverCreateTask> {
override val type: Class<DeliverCreateTask>
get() = DeliverCreateTask::class.java
}

View File

@ -31,5 +31,4 @@ data class DeliverDeleteTask(
data object DeliverDeleteTaskDef : TaskDefinition<DeliverDeleteTask> {
override val type: Class<DeliverDeleteTask>
get() = DeliverDeleteTask::class.java
}

View File

@ -31,5 +31,4 @@ data class DeliverUndoTask(
data object DeliverUndoTaskDef : TaskDefinition<DeliverUndoTask> {
override val type: Class<DeliverUndoTask>
get() = DeliverUndoTask::class.java
}

View File

@ -84,7 +84,7 @@ jackson = ["jackson-databind", "jackson-module-kotlin"]
[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
spring-boot = { id = "org.springframework.boot", version = "3.2.3" }
spring-boot = { id = "org.springframework.boot", version = "3.2.5" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
kotlin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.6" }

View File

@ -48,4 +48,6 @@ interface OwlProducer {
* @return 公開されたタスク
*/
suspend fun <T : Task> publishTask(task: T): PublishedTask<T>
suspend fun stop()
}

View File

@ -87,4 +87,8 @@ class DefaultOwlProducer(private val defaultOwlProducerConfig: DefaultOwlProduce
now
)
}
override suspend fun stop() {
defaultOwlProducerConfig.channel.shutdownNow()
}
}

View File

@ -19,6 +19,7 @@ package dev.usbharu.owl.producer.defaultimpl
import dev.usbharu.owl.common.property.PropertySerializerFactory
import dev.usbharu.owl.producer.api.OwlProducerConfig
import io.grpc.Channel
import io.grpc.ManagedChannel
/**
* デフォルトの[dev.usbharu.owl.producer.api.OwlProducer]の構成
@ -28,7 +29,7 @@ class DefaultOwlProducerConfig : OwlProducerConfig {
/**
* gRPCで使用する[Channel]
*/
lateinit var channel: Channel
lateinit var channel: ManagedChannel
/**
* プロデューサー名

View File

@ -55,4 +55,8 @@ class EmbeddedGrpcOwlProducer(
override suspend fun <T : Task> publishTask(task: T): PublishedTask<T> {
return config.owlProducer.publishTask(task)
}
override suspend fun stop() {
config.owlProducer.stop()
}
}

View File

@ -27,6 +27,7 @@ import dev.usbharu.owl.common.task.Task
import dev.usbharu.owl.common.task.TaskDefinition
import dev.usbharu.owl.producer.api.OwlProducer
import org.koin.core.Koin
import org.koin.core.context.GlobalContext
import org.koin.core.context.GlobalContext.startKoin
import org.koin.dsl.module
import org.koin.ksp.generated.defaultModule
@ -42,9 +43,12 @@ class EmbeddedOwlProducer(
private lateinit var application: Koin
private lateinit var brokerApplication: OwlBrokerApplication
private val taskMap: MutableMap<Class<*>, TaskDefinition<*>> = mutableMapOf()
override suspend fun start() {
GlobalContext.stopKoin()
application = startKoin {
printLogger()
@ -71,7 +75,8 @@ class EmbeddedOwlProducer(
)
)
application.get<OwlBrokerApplication>().start(embeddedOwlProducerConfig.port.toInt())
brokerApplication = application.get<OwlBrokerApplication>()
brokerApplication.start(embeddedOwlProducerConfig.port.toInt())
}
override suspend fun <T : Task> registerTask(taskDefinition: TaskDefinition<T>) {
@ -108,4 +113,8 @@ class EmbeddedOwlProducer(
Instant.now()
)
}
override suspend fun stop() {
brokerApplication.stop()
}
}