diff --git a/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt b/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt index 91f3f5d2c..fac9bc453 100644 --- a/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt +++ b/mirai-core/src/commonTest/kotlin/network/framework/AbstractRealNetworkHandlerTest.kt @@ -152,4 +152,5 @@ internal abstract class AbstractRealNetworkHandlerTest<H : NetworkHandler> : Abs assertEquals(state, network.state) } + val eventDispatcher get() = bot.components[EventDispatcher] } \ No newline at end of file diff --git a/mirai-core/src/commonTest/kotlin/network/handler/SelectorNetworkHandlerTest.kt b/mirai-core/src/commonTest/kotlin/network/handler/SelectorNetworkHandlerTest.kt index 2a4cd90d1..bbe7cce80 100644 --- a/mirai-core/src/commonTest/kotlin/network/handler/SelectorNetworkHandlerTest.kt +++ b/mirai-core/src/commonTest/kotlin/network/handler/SelectorNetworkHandlerTest.kt @@ -60,6 +60,15 @@ internal class SelectorNetworkHandlerTest : AbstractRealNetworkHandlerTest<Selec */ @Test fun `can recover on heartbeat failure`() = runBlockingUnit { + testReceiver { HeartbeatFailedException("test", null) } // NetworkException + } + + @Test + fun `cannot recover on other failures`() = runBlockingUnit { + testReceiver { IllegalStateException() } + } + + private suspend fun testReceiver(exception: () -> Exception) { val heartbeatScheduler = object : HeartbeatScheduler { lateinit var onHeartFailure: HeartbeatFailureHandler override fun launchJobsIn( @@ -77,7 +86,7 @@ internal class SelectorNetworkHandlerTest : AbstractRealNetworkHandlerTest<Selec bot.network.context[EventDispatcher].joinBroadcast() assertState(NetworkHandler.State.OK) - heartbeatScheduler.onHeartFailure("Test", HeartbeatFailedException("test", null)) + heartbeatScheduler.onHeartFailure("Test", exception()) assertState(NetworkHandler.State.CLOSED) bot.network.resumeConnection() // in real, this is called by BotOnlineWatchdog in SelectorNetworkHandler diff --git a/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyBotNormalLoginTest.kt b/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyBotNormalLoginTest.kt index 5fc76b112..4fb7129dc 100644 --- a/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyBotNormalLoginTest.kt +++ b/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyBotNormalLoginTest.kt @@ -10,19 +10,10 @@ package net.mamoe.mirai.internal.network.impl.netty import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.launch -import net.mamoe.mirai.event.events.BotEvent -import net.mamoe.mirai.event.events.BotOfflineEvent -import net.mamoe.mirai.event.events.BotReloginEvent -import net.mamoe.mirai.event.nextEvent -import net.mamoe.mirai.internal.network.handler.NetworkHandler.State.OK -import net.mamoe.mirai.internal.test.assertEventBroadcasts import net.mamoe.mirai.internal.test.runBlockingUnit -import net.mamoe.mirai.utils.firstIsInstanceOrNull import org.junit.jupiter.api.Test import java.io.IOException import kotlin.test.assertFailsWith -import kotlin.test.assertNotNull internal class NettyBotNormalLoginTest : AbstractNettyNHTest() { class CusLoginException(message: String?) : RuntimeException(message) @@ -44,24 +35,4 @@ internal class NettyBotNormalLoginTest : AbstractNettyNHTest() { bot.login() } } - - @Test - fun `test errors after logon`() = runBlockingUnit { - bot.login() - eventDispatcher.joinBroadcast() - assertEventBroadcasts<BotEvent>(-1) { - launch { - eventDispatcher.joinBroadcast() - channel.pipeline().fireExceptionCaught(CusLoginException("Net error")) - } - assertNotNull( - nextEvent<BotReloginEvent>(5000) { it.bot === bot } - ) - }.let { events -> - assertFailsWith<CusLoginException>("Net error") { - throw events.firstIsInstanceOrNull<BotOfflineEvent.Dropped>()!!.cause!! - } - } - assertState(OK) - } } diff --git a/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyHandlerEventTest.kt b/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyHandlerEventTest.kt index 94cb8ecf1..f22d943ad 100644 --- a/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyHandlerEventTest.kt +++ b/mirai-core/src/commonTest/kotlin/network/impl/netty/NettyHandlerEventTest.kt @@ -10,7 +10,6 @@ package net.mamoe.mirai.internal.network.impl.netty import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.awaitCancellation import net.mamoe.mirai.event.Event import net.mamoe.mirai.event.broadcast import net.mamoe.mirai.event.events.BotOfflineEvent @@ -72,22 +71,6 @@ internal class NettyHandlerEventTest : AbstractNettyNHTest() { } - @Test - fun `from OK TO CONNECTING`() = runBlockingUnit { - setSsoProcessor { - awaitCancellation() - } - assertState(INITIALIZED) - network.setStateOK(channel) - eventDispatcher.joinBroadcast() // ignore events - assertEventBroadcasts<Event>(1) { - network.setStateConnecting() - eventDispatcher.joinBroadcast() - }.let { event -> - assertEquals(BotOfflineEvent.Dropped::class, event[0]::class) - } - } - @Test fun `from CONNECTING TO OK the first time`() = runBlockingUnit { val ok = CompletableDeferred<Unit>()