@@ -4,7 +4,6 @@ import io.kotest.assertions.timing.eventually
44import io.kotest.assertions.until.Interval
55import io.kotest.assertions.until.fibonacci
66import io.kotest.assertions.withClue
7- import io.kotest.core.spec.IsolationMode
87import io.kotest.core.spec.style.WordSpec
98import io.kotest.matchers.collections.shouldBeEmpty
109import io.kotest.matchers.collections.shouldHaveSize
@@ -27,7 +26,6 @@ suspend fun await(clue: String? = null, duration: Duration = 1.seconds, interval
2726
2827@ExperimentalTime
2928class LobbyRequestTest : WordSpec ({
30- isolationMode = IsolationMode .SingleInstance
3129 " A Lobby with connected clients" When {
3230 val lobby = autoClose(TestLobby ())
3331 val players = Array (3) { lobby.connectClient("localhost", lobby.serverPort) }
@@ -42,53 +40,54 @@ class LobbyRequestTest: WordSpec({
4240 }
4341 }
4442 val admin = players[0 ]
45- " preparing a paused game" should {
43+ " a game is prepared paused " should {
4644 val listener = TestLobbyClientListener ()
4745 admin.addListener(listener)
4846 admin.authenticate(PASSWORD )
4947
50- " prepare the GameRoom" {
51- admin.prepareGame(TestPlugin .TEST_PLUGIN_UUID , true)
52- await { listener.gamePreparedReceived shouldBe true }
53- lobby.games shouldHaveSize 2
54- }
48+ admin.prepareGame(TestPlugin .TEST_PLUGIN_UUID , true)
49+ await("GameRoom prepared") { listener.gamePreparedReceived shouldBe true }
50+ lobby.games shouldHaveSize 1
5551
5652 val roomId = listener.prepareGameResponse.roomId
5753 val room = lobby.findRoom(roomId)
58- " create an empty paused game " {
54+ withClue(" GameRoom is empty and paused") {
5955 room.clients.shouldBeEmpty()
6056 room.isPauseRequested shouldBe true
6157 }
6258
6359 val observer = admin.observeAndControl(roomId, true)
64- await { listener.observedReceived shouldBe true }
60+ await(" Game observed") { println(listener); listener.observedReceived shouldBe true }
6561
66- " let players join by reservation" {
67- val reservations = listener.prepareGameResponse.reservations
68- players[1 ].joinPreparedGame(reservations[0])
69- players[2 ].joinPreparedGame(reservations[1])
70- await { room.status shouldBe GameRoom .GameStatus .ACTIVE }
71- }
62+ val reservations = listener.prepareGameResponse.reservations
63+ players[1 ].joinPreparedGame(reservations[0])
64+ await("First player joined") { room.clients shouldHaveSize 1 }
65+ players[2 ].joinPreparedGame(reservations[1])
66+ await("Players join, Game start") { room.status shouldBe GameRoom .GameStatus .ACTIVE }
7267
7368 val playerListeners = room.slots.map { slot ->
7469 PlayerListener ().also { listener -> slot.role.player.addPlayerListener(listener) }
7570 }
76- " start game on unpause" {
71+ " terminate when a Move is received while still paused" {
72+ players[1 ].sendMessageToRoom(roomId, TestMove (0))
73+ await("Terminates ") { room.status shouldBe GameRoom .GameStatus .OVER }
74+ }
75+ " play game on unpause" {
7776 observer.unpause()
7877 await { room.isPauseRequested shouldBe false }
79- }
80- val game = room.game as TestGame
81- " accept moves" {
82- playerListeners[0 ].waitForMessage(MoveRequest ::class)
83- players[1 ].sendMessageToRoom(roomId, TestMove (32))
84- await { game.currentState.state shouldBe 32 }
85- playerListeners[1 ].waitForMessage(MoveRequest ::class)
86- players[2 ].sendMessageToRoom(roomId, TestMove (54))
87- await { game.currentState.state shouldBe 54 }
88- }
89- " terminate when wrong player sends a move" {
78+ val game = room.game as TestGame
79+ withClue("Processes moves") {
80+ playerListeners[0 ].waitForMessage(MoveRequest ::class)
81+ players[1 ].sendMessageToRoom(roomId, TestMove (32))
82+ await { game.currentState.state shouldBe 32 }
83+ playerListeners[1 ].waitForMessage(MoveRequest ::class)
84+ players[2 ].sendMessageToRoom(roomId, TestMove (54))
85+ await { game.currentState.state shouldBe 54 }
86+ }
9087 players[2 ].sendMessageToRoom(roomId, TestMove (0))
91- await { room.status shouldBe GameRoom .GameStatus .OVER }
88+ await("Terminate after wrong player sent a turn") {
89+ room.status shouldBe GameRoom .GameStatus .OVER
90+ }
9291 }
9392 }
9493 }
0 commit comments