diff --git a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/Monkey.kt b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/Monkey.kt index acaf428ec81..1db7b3e3766 100644 --- a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/Monkey.kt +++ b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/Monkey.kt @@ -40,6 +40,7 @@ import com.wire.kalium.logic.feature.publicuser.GetAllContactsResult import com.wire.kalium.monkeys.importer.Backend import com.wire.kalium.monkeys.importer.UserCount import com.wire.kalium.monkeys.importer.UserData +import com.wire.kalium.monkeys.logger import com.wire.kalium.monkeys.pool.ConversationPool import com.wire.kalium.monkeys.pool.MonkeyPool import com.wire.kalium.monkeys.pool.resolveUserCount @@ -127,9 +128,24 @@ class Monkey(val monkeyType: MonkeyType) { this.monkeyState = MonkeyState.NotReady error("Failed registering client of monkey ${this.monkeyType.userData().email}: $registerResult") } - sessionScope.observeSyncState().first { it is SyncState.Live } - this.monkeyState = MonkeyState.Ready(sessionScope) - callback(this) + var isFinished: Boolean + do { + val state = sessionScope.observeSyncState().first { it !is SyncState.Waiting && it !is SyncState.SlowSync } + when (state) { + is SyncState.Failed -> { + this.monkeyState = MonkeyState.NotReady + logger.w("Failed logging in: ${state.cause}") + isFinished = !state.cause.isRetryable + } + is SyncState.GatheringPendingEvents, + is SyncState.Live -> { + this.monkeyState = MonkeyState.Ready(sessionScope) + callback(this) + isFinished = true + } + else -> error("This should have been done") + } + } while (!isFinished) } private suspend fun connectedMonkeys(): List { diff --git a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/pool/MonkeyPool.kt b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/pool/MonkeyPool.kt index 104bc9872f3..77ad109d5e2 100644 --- a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/pool/MonkeyPool.kt +++ b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/pool/MonkeyPool.kt @@ -26,8 +26,6 @@ import com.wire.kalium.monkeys.importer.Team import com.wire.kalium.monkeys.importer.UserCount import com.wire.kalium.monkeys.importer.UserData import io.micrometer.core.instrument.Tag -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.launch import java.util.concurrent.ConcurrentHashMap import kotlin.math.roundToInt @@ -69,13 +67,11 @@ class MonkeyPool(users: List, testCase: String) { } } - suspend fun warmUp(core: CoreLogic) = coroutineScope { + suspend fun warmUp(core: CoreLogic) { // this is needed to create key packages for clients at least once poolById.values.forEach { - launch { - it.login(core) {} - it.logout {} - } + it.login(core) {} + it.logout {} } }