@@ -16,14 +16,19 @@ import sc.protocol.requests.JoinPreparedRoomRequest
16
16
import sc.protocol.requests.PrepareGameRequest
17
17
import sc.protocol.responses.ErrorPacket
18
18
import sc.protocol.responses.GamePreparedResponse
19
+ import sc.protocol.responses.ObservationResponse
19
20
import sc.protocol.room.ErrorMessage
21
+ import sc.protocol.room.GamePaused
22
+ import sc.protocol.room.MementoMessage
23
+ import sc.protocol.room.ObservableRoomMessage
20
24
import sc.server.client.MessageListener
21
25
import sc.server.client.PlayerListener
22
26
import sc.server.gaming.GameRoom
23
27
import sc.server.helpers.TestTeam
24
28
import sc.server.plugins.TestGame
25
29
import sc.server.plugins.TestMove
26
30
import sc.server.plugins.TestPlugin
31
+ import sc.shared.GameResult
27
32
import sc.shared.SlotDescriptor
28
33
import kotlin.time.Duration
29
34
import kotlin.time.ExperimentalTime
@@ -92,15 +97,15 @@ class LobbyRequestTest: WordSpec({
92
97
await { room.isPauseRequested shouldBe false }
93
98
val game = room.game as TestGame
94
99
game.isPaused shouldBe false
100
+ await("game started") { game.activePlayer?.color shouldBe TestTeam .RED }
95
101
withClue("Processes moves") {
96
- game.activePlayer?.color shouldBe TestTeam .RED
97
- // TODO occasional failure
98
102
playerListeners[0 ].waitForMessage(MoveRequest ::class)
99
103
players[0 ].sendMessageToRoom(roomId, TestMove (1))
100
- await { game.currentState.state shouldBe 1 }
101
- game.activePlayer?.color shouldBe TestTeam . BLUE
104
+ await { game.activePlayer?.color shouldBe TestTeam . BLUE }
105
+ game.currentState.state shouldBe 1
102
106
playerListeners[1 ].waitForMessage(MoveRequest ::class)
103
107
players[1 ].sendMessageToRoom(roomId, TestMove (2))
108
+ await { game.activePlayer?.color shouldBe TestTeam .RED }
104
109
await { game.currentState.state shouldBe 2 }
105
110
}
106
111
@@ -116,8 +121,8 @@ class LobbyRequestTest: WordSpec({
116
121
}
117
122
" a game is prepared with descriptors" should {
118
123
val descriptors = arrayOf(
119
- SlotDescriptor ("supreme", reserved = true),
120
- SlotDescriptor ("human", canTimeout = false, reserved = false),
124
+ SlotDescriptor ("supreme", canTimeout = false, reserved = true),
125
+ SlotDescriptor ("human", reserved = false),
121
126
)
122
127
val prepared = prepareGame(PrepareGameRequest (TestPlugin .TEST_PLUGIN_UUID , descriptors, pause = false))
123
128
val room = lobby.findRoom(prepared.roomId)
@@ -133,16 +138,39 @@ class LobbyRequestTest: WordSpec({
133
138
slot.isReserved shouldBe descriptor.reserved
134
139
}
135
140
}
136
- players[0 ].joinGameRoom(prepared.roomId)
141
+ players[1 ].joinGameRoom(prepared.roomId)
137
142
" join player into nonreserved slot" {
138
143
await { room.clients shouldHaveSize 1 }
139
144
room.slots[0 ].isEmpty shouldBe true
140
145
room.slots[0 ].isFree shouldBe false
141
146
room.slots[1 ].isEmpty shouldBe false
142
147
}
143
- players[1 ].joinGameWithReservation(prepared.reservations.single())
144
- await("start game when two players joined") {
145
- room.status shouldBe GameRoom .GameStatus .ACTIVE
148
+
149
+ val roomListener = MessageListener <ObservableRoomMessage >()
150
+ withClue("accept observation") {
151
+ admin.observe(prepared.roomId, roomListener::addMessage)
152
+ adminListener.waitForMessage(ObservationResponse ::class)
153
+ }
154
+
155
+ players[0 ].joinGameWithReservation(prepared.reservations.single())
156
+ " react to controller" {
157
+ await("game start") {
158
+ room.isPauseRequested shouldBe false
159
+ room.status shouldBe GameRoom .GameStatus .ACTIVE
160
+ }
161
+ roomListener.waitForMessage(MementoMessage ::class)
162
+
163
+ val controller = admin.control(prepared.roomId)
164
+ controller.pause()
165
+ // TODO pausing is currently not acknowledged
166
+ // roomListener.waitForMessage(GamePaused::class)
167
+ withClue("appropriate result for aborted game") {
168
+ players[1 ].sendMessageToRoom(prepared.roomId, TestMove (0))
169
+ val result = roomListener.waitForMessage(GameResult ::class)
170
+ // TODO can be checked once moved from plugin to sdk
171
+ // result.isRegular shouldBe false
172
+ result.winners?.singleOrNull() shouldBe room.game.players.first()
173
+ }
146
174
}
147
175
}
148
176
}
0 commit comments