summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-09-14 00:50:29 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-09-14 00:50:29 +0200
commit735cbbdf98befb25cef38c2b2abe6c70d6414b13 (patch)
tree5a41f385c84cd1e45024f13a9004606eb17f02ec
parentSimplify local run docker command (with DockerHub) (diff)
downloadseven-wonders-735cbbdf98befb25cef38c2b2abe6c70d6414b13.tar.gz
seven-wonders-735cbbdf98befb25cef38c2b2abe6c70d6414b13.tar.bz2
seven-wonders-735cbbdf98befb25cef38c2b2abe6c70d6414b13.zip
Upgrade to Krossbow 0.41.0
-rw-r--r--sw-client/build.gradle.kts2
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt28
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/SevenWondersTest.kt12
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 <reified T : Any, reified U : Any> StompSessionWithKx
payload: T? = null,
serializer: SerializationStrategy<T>,
deserializer: DeserializationStrategy<U>,
-): 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<ErrorDTO> = stompSession.subscribe("/user/queue/errors", ErrorDTO.serializer())
+ suspend fun watchErrors(): Flow<ErrorDTO> = 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<List<LobbyDTO>> =
+ suspend fun watchGames(): Flow<List<LobbyDTO>> =
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<LobbyDTO> = stompSession.subscribe("/user/queue/lobby/updated", LobbyDTO.serializer())
+ suspend fun watchLobbyUpdates(): Flow<LobbyDTO> =
+ 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<String> =
+ suspend fun watchPlayerReady(gameId: Long): Flow<String> =
stompSession.subscribe("/topic/game/$gameId/playerReady", String.serializer())
- fun watchPreparedCards(gameId: Long): Flow<PreparedCard> =
+ suspend fun watchPreparedCards(gameId: Long): Flow<PreparedCard> =
stompSession.subscribe("/topic/game/$gameId/prepared", PreparedCard.serializer())
- fun watchTurns(): Flow<PlayerTurnInfo> =
+ suspend fun watchTurns(): Flow<PlayerTurnInfo> =
stompSession.subscribe("/user/queue/game/turn", PlayerTurnInfo.serializer())
suspend fun sayReady() {
stompSession.sendEmptyMsg("/app/game/sayReady")
}
- fun watchOwnMoves(): Flow<PlayerMove> =
+ suspend fun watchOwnMoves(): Flow<PlayerMove> =
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)
bgstack15