From 735cbbdf98befb25cef38c2b2abe6c70d6414b13 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Mon, 14 Sep 2020 00:50:29 +0200 Subject: Upgrade to Krossbow 0.41.0 --- sw-client/build.gradle.kts | 2 +- .../sevenwonders/client/SevenWondersClient.kt | 28 +++++++++------------- .../luxons/sevenwonders/server/SevenWondersTest.kt | 12 ---------- 3 files changed, 12 insertions(+), 30 deletions(-) diff --git a/sw-client/build.gradle.kts b/sw-client/build.gradle.kts index 8e565745..e3f75f87 100644 --- a/sw-client/build.gradle.kts +++ b/sw-client/build.gradle.kts @@ -2,7 +2,7 @@ plugins { kotlin("multiplatform") } -val krossbowVersion = "0.30.1" +val krossbowVersion = "0.41.0" kotlin { jvm() diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt index 05c6bf94..9a9fe356 100644 --- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt +++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt @@ -1,10 +1,6 @@ package org.luxons.sevenwonders.client -import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.async -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first import kotlinx.serialization.DeserializationStrategy @@ -61,20 +57,17 @@ private suspend inline fun StompSessionWithKx payload: T? = null, serializer: SerializationStrategy, deserializer: DeserializationStrategy, -): U = coroutineScope { - val sub = async(start = CoroutineStart.UNDISPATCHED) { - subscribe(receiveDestination, deserializer).first() - } - delay(30) // ensures the subscription happened +): U { + val sub = subscribe(receiveDestination, deserializer) convertAndSend(sendDestination, payload, serializer) - sub.await() + return sub.first() } class SevenWondersSession(private val stompSession: StompSessionWithKxSerialization) { suspend fun disconnect() = stompSession.disconnect() - fun watchErrors(): Flow = stompSession.subscribe("/user/queue/errors", ErrorDTO.serializer()) + suspend fun watchErrors(): Flow = stompSession.subscribe("/user/queue/errors", ErrorDTO.serializer()) suspend fun chooseName(displayName: String, icon: Icon? = null): ConnectedPlayer = stompSession.request( sendDestination = "/app/chooseName", @@ -84,7 +77,7 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat deserializer = ConnectedPlayer.serializer(), ) - fun watchGames(): Flow> = + suspend fun watchGames(): Flow> = stompSession.subscribe("/topic/games", ListSerializer(LobbyDTO.serializer())) suspend fun createGame(gameName: String): LobbyDTO = stompSession.request( @@ -135,7 +128,8 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat ) } - fun watchLobbyUpdates(): Flow = stompSession.subscribe("/user/queue/lobby/updated", LobbyDTO.serializer()) + suspend fun watchLobbyUpdates(): Flow = + stompSession.subscribe("/user/queue/lobby/updated", LobbyDTO.serializer()) suspend fun awaitGameStart(gameId: Long): PlayerTurnInfo { val startEvents = stompSession.subscribe("/user/queue/lobby/$gameId/started", PlayerTurnInfo.serializer()) @@ -146,20 +140,20 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat stompSession.sendEmptyMsg("/app/lobby/startGame") } - fun watchPlayerReady(gameId: Long): Flow = + suspend fun watchPlayerReady(gameId: Long): Flow = stompSession.subscribe("/topic/game/$gameId/playerReady", String.serializer()) - fun watchPreparedCards(gameId: Long): Flow = + suspend fun watchPreparedCards(gameId: Long): Flow = stompSession.subscribe("/topic/game/$gameId/prepared", PreparedCard.serializer()) - fun watchTurns(): Flow = + suspend fun watchTurns(): Flow = stompSession.subscribe("/user/queue/game/turn", PlayerTurnInfo.serializer()) suspend fun sayReady() { stompSession.sendEmptyMsg("/app/game/sayReady") } - fun watchOwnMoves(): Flow = + suspend fun watchOwnMoves(): Flow = stompSession.subscribe("/user/queue/game/preparedMove", PlayerMove.serializer()) suspend fun prepareMove(move: PlayerMove) { diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/SevenWondersTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/SevenWondersTest.kt index 0150258c..2518a735 100644 --- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/SevenWondersTest.kt +++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/SevenWondersTest.kt @@ -1,7 +1,6 @@ package org.luxons.sevenwonders.server import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.produceIn import kotlinx.coroutines.launch import kotlinx.coroutines.withTimeout @@ -55,32 +54,22 @@ class SevenWondersTest { @Test fun lobbySubscription_ignoredForOutsiders() = runAsyncTest { - System.err.println("before new player owner") val ownerSession = newPlayer("GameOwner") - System.err.println("before new player 1") val session1 = newPlayer("Player1") - System.err.println("before new player 2") val session2 = newPlayer("Player2") val gameName = "Test Game" - System.err.println("before create game") val lobby = ownerSession.createGame(gameName) - System.err.println("before join game 1") session1.joinGame(lobby.id) - System.err.println("before join game 2") session2.joinGame(lobby.id) - System.err.println("before new outsider player") val outsiderSession = newPlayer("Outsider") val started = launch { outsiderSession.awaitGameStart(lobby.id) } - System.err.println("before start game") ownerSession.startGame() val nothing = withTimeoutOrNull(50) { started.join() } assertNull(nothing) started.cancel() - System.err.println("before disconnect") disconnect(ownerSession, session1, session2, outsiderSession) - System.err.println("after disconnect") } @Test @@ -133,7 +122,6 @@ class SevenWondersTest { launch { session.awaitGameStart(lobby.id) val turns = session.watchTurns().produceIn(this) - delay(100) // ensures the subscription happened session.sayReady() val turn = turns.receive() assertNotNull(turn) -- cgit