mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-01 03:50:18 +08:00
Do not listen BotOfflineEvent to close network
This commit is contained in:
parent
44ef95a4d0
commit
0d28772275
@ -42,7 +42,7 @@ private data class BotClosedByEvent(val event: BotOfflineEvent) : RuntimeExcepti
|
|||||||
|
|
||||||
internal class BotOfflineEventMonitorImpl : BotOfflineEventMonitor {
|
internal class BotOfflineEventMonitorImpl : BotOfflineEventMonitor {
|
||||||
override fun attachJob(bot: AbstractBot, scope: CoroutineScope) {
|
override fun attachJob(bot: AbstractBot, scope: CoroutineScope) {
|
||||||
return
|
return // leave it until 2.7-RC
|
||||||
bot.eventChannel.parentScope(scope).subscribeAlways(
|
bot.eventChannel.parentScope(scope).subscribeAlways(
|
||||||
::onEvent,
|
::onEvent,
|
||||||
priority = EventPriority.MONITOR,
|
priority = EventPriority.MONITOR,
|
||||||
|
@ -12,11 +12,7 @@ package net.mamoe.mirai.internal.network.impl.netty
|
|||||||
import kotlinx.coroutines.CoroutineName
|
import kotlinx.coroutines.CoroutineName
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import net.mamoe.mirai.event.broadcast
|
|
||||||
import net.mamoe.mirai.event.events.BotOfflineEvent
|
|
||||||
import net.mamoe.mirai.internal.MockBot
|
import net.mamoe.mirai.internal.MockBot
|
||||||
import net.mamoe.mirai.internal.network.components.BotOfflineEventMonitor
|
|
||||||
import net.mamoe.mirai.internal.network.components.BotOfflineEventMonitorImpl
|
|
||||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler.State.*
|
import net.mamoe.mirai.internal.network.handler.NetworkHandler.State.*
|
||||||
import net.mamoe.mirai.internal.test.runBlockingUnit
|
import net.mamoe.mirai.internal.test.runBlockingUnit
|
||||||
import net.mamoe.mirai.supervisorJob
|
import net.mamoe.mirai.supervisorJob
|
||||||
@ -27,27 +23,30 @@ import kotlin.test.assertTrue
|
|||||||
|
|
||||||
internal class NettyBotLifecycleTest : AbstractNettyNHTest() {
|
internal class NettyBotLifecycleTest : AbstractNettyNHTest() {
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `closed on Force offline with BotOfflineEventMonitor`() = runBlockingUnit {
|
|
||||||
defaultComponents[BotOfflineEventMonitor] = BotOfflineEventMonitorImpl()
|
|
||||||
bot.login()
|
|
||||||
assertState(OK)
|
|
||||||
BotOfflineEvent.Force(bot, "test", "test").broadcast()
|
|
||||||
assertState(CLOSED)
|
|
||||||
assertFalse { network.isActive }
|
|
||||||
assertTrue { bot.isActive }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
// not allowed anymore
|
||||||
fun `closed on Active offline with BotOfflineEventMonitor`() = runBlockingUnit {
|
|
||||||
defaultComponents[BotOfflineEventMonitor] = BotOfflineEventMonitorImpl()
|
// @Test
|
||||||
bot.login()
|
// fun `closed on Force offline with BotOfflineEventMonitor`() = runBlockingUnit {
|
||||||
assertState(OK)
|
// defaultComponents[BotOfflineEventMonitor] = BotOfflineEventMonitorImpl()
|
||||||
BotOfflineEvent.Active(bot, null).broadcast()
|
// bot.login()
|
||||||
assertState(CLOSED)
|
// assertState(OK)
|
||||||
assertFalse { network.isActive }
|
// BotOfflineEvent.Force(bot, "test", "test").broadcast()
|
||||||
assertTrue { bot.isActive }
|
// assertState(CLOSED)
|
||||||
}
|
// assertFalse { network.isActive }
|
||||||
|
// assertTrue { bot.isActive }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// fun `closed on Active offline with BotOfflineEventMonitor`() = runBlockingUnit {
|
||||||
|
// defaultComponents[BotOfflineEventMonitor] = BotOfflineEventMonitorImpl()
|
||||||
|
// bot.login()
|
||||||
|
// assertState(OK)
|
||||||
|
// BotOfflineEvent.Active(bot, null).broadcast()
|
||||||
|
// assertState(CLOSED)
|
||||||
|
// assertFalse { network.isActive }
|
||||||
|
// assertTrue { bot.isActive }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user