summaryrefslogtreecommitdiff
path: root/sw-server/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sw-server/src/test')
-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