mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-01 22:00:46 +08:00
Cancel TestEventDispatcher jobs after test
This commit is contained in:
parent
a964f7ee87
commit
c260abb6f3
@ -30,6 +30,7 @@ import net.mamoe.mirai.utils.MiraiLogger
|
||||
import network.framework.components.TestEventDispatcherImpl
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.AfterTest
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
@ -46,6 +47,14 @@ internal abstract class AbstractMockNetworkHandlerTest : AbstractNetworkHandlerT
|
||||
}
|
||||
}
|
||||
protected val logger = MiraiLogger.Factory.create(Bot::class, "test")
|
||||
|
||||
private val eventDispatcherJob = SupervisorJob()
|
||||
|
||||
@AfterTest
|
||||
private fun cancelJob() {
|
||||
eventDispatcherJob.cancel()
|
||||
}
|
||||
|
||||
protected val components = ConcurrentComponentStorage().apply {
|
||||
set(SsoProcessor, TestSsoProcessor(bot))
|
||||
set(
|
||||
@ -53,7 +62,7 @@ internal abstract class AbstractMockNetworkHandlerTest : AbstractNetworkHandlerT
|
||||
// Note that in real we use 'bot.coroutineContext', but here we override with a new, independent job
|
||||
// to allow BotOfflineEvent.Active to be broadcast and joinBroadcast works even if bot coroutineScope is closed.
|
||||
TestEventDispatcherImpl(
|
||||
bot.coroutineContext + SupervisorJob(),
|
||||
bot.coroutineContext + eventDispatcherJob,
|
||||
bot.logger.subLogger("TestEventDispatcherImpl")
|
||||
)
|
||||
)
|
||||
|
@ -89,6 +89,13 @@ internal abstract class AbstractRealNetworkHandlerTest<H : NetworkHandler> : Abs
|
||||
|
||||
val nhEvents = ConcurrentLinkedQueue<NHEvent>()
|
||||
|
||||
private val eventDispatcherJob = SupervisorJob()
|
||||
|
||||
@AfterTest
|
||||
private fun cancelJob() {
|
||||
eventDispatcherJob.cancel()
|
||||
}
|
||||
|
||||
/**
|
||||
* This overrides [QQAndroidBot.components]
|
||||
*/
|
||||
@ -149,7 +156,7 @@ internal abstract class AbstractRealNetworkHandlerTest<H : NetworkHandler> : Abs
|
||||
// Note that in real we use 'bot.coroutineContext', but here we override with a new, independent job
|
||||
// to allow BotOfflineEvent.Active to be broadcast and joinBroadcast works even if bot coroutineScope is closed.
|
||||
TestEventDispatcherImpl(
|
||||
bot.coroutineContext + SupervisorJob(),
|
||||
bot.coroutineContext + eventDispatcherJob,
|
||||
bot.logger.subLogger("TestEventDispatcherImpl")
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user