summaryrefslogtreecommitdiff
path: root/sw-server/src/test/kotlin
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-17 18:22:23 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-21 11:31:36 +0200
commitc4d9e5e9467130de09b7810097c0b3779219ffe0 (patch)
tree1bf7f326745672e3e0ba749bee21d420eea84f38 /sw-server/src/test/kotlin
parentFix background->backgrounds path (diff)
downloadseven-wonders-c4d9e5e9467130de09b7810097c0b3779219ffe0.tar.gz
seven-wonders-c4d9e5e9467130de09b7810097c0b3779219ffe0.tar.bz2
seven-wonders-c4d9e5e9467130de09b7810097c0b3779219ffe0.zip
Fix SW client "request"
Diffstat (limited to 'sw-server/src/test/kotlin')
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/SevenWondersTest.kt14
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt2
2 files changed, 5 insertions, 11 deletions
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 b2b86131..90fd7df1 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,10 +1,7 @@
package org.luxons.sevenwonders.server
-import kotlinx.coroutines.FlowPreview
+import kotlinx.coroutines.*
import kotlinx.coroutines.flow.produceIn
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withTimeout
-import kotlinx.coroutines.withTimeoutOrNull
import org.junit.runner.RunWith
import org.luxons.sevenwonders.client.SevenWondersClient
import org.luxons.sevenwonders.client.SevenWondersSession
@@ -13,11 +10,9 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.test.context.junit4.SpringRunner
-import kotlin.test.assertEquals
-import kotlin.test.assertNotNull
-import kotlin.test.assertNull
-import kotlin.test.Test
+import kotlin.test.*
+@OptIn(FlowPreview::class)
@RunWith(SpringRunner::class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class SevenWondersTest {
@@ -83,7 +78,6 @@ class SevenWondersTest {
disconnect(ownerSession)
}
- @OptIn(FlowPreview::class)
@Test
fun createGame_seenByConnectedPlayers() = runAsyncTest {
val otherSession = newPlayer("OtherPlayer")
@@ -107,7 +101,6 @@ class SevenWondersTest {
disconnect(ownerSession, otherSession)
}
- @OptIn(FlowPreview::class)
@Test
fun startGame_3players() = runAsyncTest {
val session1 = newPlayer("Player1")
@@ -123,6 +116,7 @@ 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)
diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt
index 5f6c5be9..7a962368 100644
--- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt
+++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt
@@ -13,7 +13,7 @@ fun mockSimpMessagingTemplate(): SimpMessagingTemplate = SimpMessagingTemplate(o
override fun send(message: Message<*>, timeout: Long): Boolean = true
})
-fun runAsyncTest(timeoutMillis: Long = 1000, block: suspend CoroutineScope.() -> Unit) = runBlocking {
+fun runAsyncTest(timeoutMillis: Long = 3000, block: suspend CoroutineScope.() -> Unit) = runBlocking {
val result = withTimeoutOrNull(timeoutMillis, block)
assertNotNull(result, "Test timed out, exceeded ${timeoutMillis}ms")
}
bgstack15