Skip to content

Commit

Permalink
[core] Tried to fix again
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlatemp committed Jul 25, 2023
1 parent 8a8689e commit d1c6555
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcP
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.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import kotlin.test.Test
import kotlin.test.assertFalse
Expand Down Expand Up @@ -112,14 +113,15 @@ internal class AuthorizationReasonTest : AbstractBotAuthTest() {
// @Test
@RepeatedTest(20)
fun `force offline`() = runTest {
var isFirstLogin: Boolean = true
var isFirstLogin = AtomicBoolean(true)

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

setAuthorization { auth, info ->
isFirstLogin = info.isFirstLogin
isFirstLogin.set(info.isFirstLogin)
authReason.set(info.reason)
bot.logger.debug(Throwable("Stack trace"))

auth.authByPassword("")
return@setAuthorization object : BotAuthResult {}
Expand Down Expand Up @@ -150,7 +152,7 @@ internal class AuthorizationReasonTest : AbstractBotAuthTest() {
eventDispatcher.joinBroadcast() // why test finished before code reaches end??
yield()

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

0 comments on commit d1c6555

Please sign in to comment.