optimise test
This commit is contained in:
@@ -24,6 +24,7 @@ import eventDemo.business.notification.TheGameWasStartedNotification
|
|||||||
import eventDemo.business.notification.WelcomeToTheGameNotification
|
import eventDemo.business.notification.WelcomeToTheGameNotification
|
||||||
import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory
|
import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory
|
||||||
import eventDemo.testKoinApplicationWithConfig
|
import eventDemo.testKoinApplicationWithConfig
|
||||||
|
import io.kotest.assertions.nondeterministic.until
|
||||||
import io.kotest.core.spec.style.FunSpec
|
import io.kotest.core.spec.style.FunSpec
|
||||||
import io.kotest.matchers.collections.shouldHaveSize
|
import io.kotest.matchers.collections.shouldHaveSize
|
||||||
import io.kotest.matchers.equals.shouldBeEqual
|
import io.kotest.matchers.equals.shouldBeEqual
|
||||||
@@ -32,7 +33,6 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.channels.trySendBlocking
|
import kotlinx.coroutines.channels.trySendBlocking
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.joinAll
|
import kotlinx.coroutines.joinAll
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
@@ -58,6 +58,8 @@ class GameSimulationTest :
|
|||||||
var playedCard1: Card? = null
|
var playedCard1: Card? = null
|
||||||
var playedCard2: Card? = null
|
var playedCard2: Card? = null
|
||||||
|
|
||||||
|
var player1HasJoin = false
|
||||||
|
|
||||||
val player1Job =
|
val player1Job =
|
||||||
launch {
|
launch {
|
||||||
IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(gameId, player1)).also { sendCommand ->
|
IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(gameId, player1)).also { sendCommand ->
|
||||||
@@ -67,6 +69,8 @@ class GameSimulationTest :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player1HasJoin = true
|
||||||
|
|
||||||
channelNotification1.receive().let {
|
channelNotification1.receive().let {
|
||||||
assertIs<WelcomeToTheGameNotification>(it).players shouldBeEqual setOf(player1)
|
assertIs<WelcomeToTheGameNotification>(it).players shouldBeEqual setOf(player1)
|
||||||
}
|
}
|
||||||
@@ -116,7 +120,7 @@ class GameSimulationTest :
|
|||||||
|
|
||||||
val player2Job =
|
val player2Job =
|
||||||
launch {
|
launch {
|
||||||
delay(100)
|
until(1.seconds) { player1HasJoin }
|
||||||
IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(gameId, player2)).also { sendCommand ->
|
IWantToJoinTheGameCommand(IWantToJoinTheGameCommand.Payload(gameId, player2)).also { sendCommand ->
|
||||||
channelCommand2.send(sendCommand)
|
channelCommand2.send(sendCommand)
|
||||||
channelNotification2.receive().let {
|
channelNotification2.receive().let {
|
||||||
|
|||||||
Reference in New Issue
Block a user