Skip to content

Commit

Permalink
[core] Tried to fix AuthorizationReasonTest.force offline
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlatemp committed Jul 25, 2023
1 parent 061bd28 commit 8a8689e
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.mamoe.mirai.internal.network.auth

import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.yield
import net.mamoe.mirai.auth.AuthReason
import net.mamoe.mirai.auth.BotAuthResult
import net.mamoe.mirai.internal.MockAccount
Expand All @@ -22,6 +23,8 @@ import net.mamoe.mirai.internal.network.protocol.packet.IncomingPacket
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPushForceOffline
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
import net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin
import org.junit.jupiter.api.RepeatedTest
import java.util.concurrent.atomic.AtomicReference
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertIs
Expand Down Expand Up @@ -106,14 +109,17 @@ internal class AuthorizationReasonTest : AbstractBotAuthTest() {
assertIs<AuthReason.FastLoginError>(authReason)
}

@Test
// @Test
@RepeatedTest(20)
fun `force offline`() = runTest {
var isFirstLogin: Boolean = true
var authReason: AuthReason? = null

// volatile
val authReason = AtomicReference<AuthReason?>(null)

setAuthorization { auth, info ->
isFirstLogin = info.isFirstLogin
authReason = info.reason
authReason.set(info.reason)

auth.authByPassword("")
return@setAuthorization object : BotAuthResult {}
Expand Down Expand Up @@ -142,8 +148,9 @@ internal class AuthorizationReasonTest : AbstractBotAuthTest() {
)

eventDispatcher.joinBroadcast() // why test finished before code reaches end??
yield()

assertFalse(isFirstLogin)
assertIs<AuthReason.ForceOffline>(authReason)
assertIs<AuthReason.ForceOffline>(authReason.get(), message = authReason.toString())
}
}

0 comments on commit 8a8689e

Please sign in to comment.