diff options
author | Joffrey Bion <joffrey.bion@gmail.com> | 2023-04-30 23:34:22 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@gmail.com> | 2023-04-30 23:42:07 +0200 |
commit | 2f744b5f07d8b09bbb49ef2ecdc3456acdc95f34 (patch) | |
tree | 4a53bba655dfe98bb95e554c9b9062c08d651c2a /sw-server/src/test/kotlin/org | |
parent | Use kotlinx-coroutines-test in sw-ui (diff) | |
download | seven-wonders-2f744b5f07d8b09bbb49ef2ecdc3456acdc95f34.tar.gz seven-wonders-2f744b5f07d8b09bbb49ef2ecdc3456acdc95f34.tar.bz2 seven-wonders-2f744b5f07d8b09bbb49ef2ecdc3456acdc95f34.zip |
Cancel asserter collections before disconnecting in tests
Diffstat (limited to 'sw-server/src/test/kotlin/org')
-rw-r--r-- | sw-server/src/test/kotlin/org/luxons/sevenwonders/server/SevenWondersTest.kt | 10 | ||||
-rw-r--r-- | sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt | 11 |
2 files changed, 16 insertions, 5 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 bb32a79e..2b7330ec 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 @@ -59,13 +59,16 @@ class SevenWondersTest { session2.joinGameAndAwaitLobby(lobby.id) val outsiderSession = newPlayer("Outsider") - val outsiderAsserter = outsiderSession.eventAsserter(scope = this) + val outsiderAsserter = outsiderSession.eventAsserter(scope = this) val ownerAsserter = ownerSession.eventAsserter(scope = this) + ownerSession.startGame() ownerAsserter.expectGameEvent<GameEvent.GameStarted>() outsiderAsserter.expectNoGameEvent("outsider should not receive the game start event of this game") + ownerAsserter.cancel() + outsiderAsserter.cancel() disconnect(ownerSession, session1, session2, outsiderSession) } @@ -97,6 +100,7 @@ class SevenWondersTest { assertEquals(createdLobby.id, receivedLobby.id) assertEquals(createdLobby.name, receivedLobby.name) + asserter.cancel() disconnect(ownerSession, otherSession) } @@ -142,6 +146,10 @@ class SevenWondersTest { asserter2.expectPlayFromHandTurn() asserter3.expectPlayFromHandTurn() + asserter1.cancel() + asserter2.cancel() + asserter3.cancel() + session1.disconnect() session2.disconnect() session3.disconnect() diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt index 62245764..c5c4fedb 100644 --- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt +++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/ClientEventsAsserts.kt @@ -1,10 +1,8 @@ package org.luxons.sevenwonders.server.test -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.* import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.flow.produceIn -import kotlinx.coroutines.withTimeoutOrNull import org.luxons.sevenwonders.client.SevenWondersSession import org.luxons.sevenwonders.model.api.events.GameEvent import org.luxons.sevenwonders.model.api.events.GameListEvent @@ -18,7 +16,12 @@ import kotlin.time.Duration.Companion.seconds class EventAsserter( val gameListEvents: ReceiveChannel<GameListEvent>, val gameEvents: ReceiveChannel<GameEvent>, -) +) { + fun cancel() { + gameListEvents.cancel() + gameEvents.cancel() + } +} @OptIn(FlowPreview::class) suspend fun SevenWondersSession.eventAsserter(scope: CoroutineScope): EventAsserter { |