diff --git a/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt b/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt index c89b77f66a..0a326a8573 100644 --- a/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt +++ b/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt @@ -158,6 +158,13 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector("test TimeoutCancellationException") { bot.login() } + assertState(NetworkHandler.State.CLOSED) + } + // 经过 #1963 考虑后在初次登录遇到任何错误都终止并传递异常 // @Test // fun `test network broken`() = runBlockingUnit { @@ -113,9 +126,36 @@ internal class CommonNHBotNormalLoginTest : AbstractCommonNHTest() { bot.network.close(StatSvc.ReqMSFOffline.MsfOfflineToken(0, 0, 0)) eventDispatcher.joinBroadcast() - delay(1000L) // auto resume in BotOfflineEventMonitor + yield() // auto resume in BotOfflineEventMonitor eventDispatcher.joinBroadcast() assertState(NetworkHandler.State.OK) } + + // #2504, #2488 + @Test + fun `test resume failed with TimeoutCancellationException`() = runBlockingUnit { + var first = true + var failCount = 3 + setSsoProcessor { + if (first) { + first = false + } else { + if (failCount > 0) { + failCount-- + //Throw TimeoutCancellationException + withTimeout(1) { + delay(1000) + } + } + } + } + bot.login() + bot.network.close(HeartbeatFailedException("Heartbeat Timeout", RuntimeException("Timeout stub"), true)) + eventDispatcher.joinBroadcast() + yield() // auto resume in BotOfflineEventMonitor + eventDispatcher.joinBroadcast() + assertState(NetworkHandler.State.OK) + } + }