From ac1fc887c54b10bb3f1ae26eb9817281857d3c81 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 13 May 2022 22:19:08 +0100 Subject: [PATCH] Close test bot instance after each test --- .../network/framework/AbstractRealNetworkHandlerTest.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt b/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt index 8e1c8ec62..650056892 100644 --- a/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt +++ b/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt @@ -29,6 +29,7 @@ import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.debug import net.mamoe.mirai.utils.lateinitMutableProperty import network.framework.components.TestEventDispatcherImpl +import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.TestInstance import java.net.InetSocketAddress import java.util.concurrent.ConcurrentLinkedQueue @@ -44,7 +45,13 @@ internal sealed class AbstractRealNetworkHandlerTest : Abstr abstract val factory: NetworkHandlerFactory abstract val network: H - var bot: QQAndroidBot by lateinitMutableProperty { createBot() } + private var botInit = false + var bot: QQAndroidBot by lateinitMutableProperty { botInit = true; createBot() } + + @AfterEach + fun afterEach() { + if (botInit) bot.close() + } protected open fun createBot(account: BotAccount = MockAccount): QQAndroidBot { return object : QQAndroidBot(account, MockConfiguration.copy()) {