Skip to content

Commit d7777de

Browse files
committed
test(server): add tests for AdminClient
1 parent 86dbcd6 commit d7777de

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

server/test/sc/server/network/LobbyRequestTest.kt

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ import sc.protocol.requests.JoinPreparedRoomRequest
1616
import sc.protocol.requests.PrepareGameRequest
1717
import sc.protocol.responses.ErrorPacket
1818
import sc.protocol.responses.GamePreparedResponse
19+
import sc.protocol.responses.ObservationResponse
1920
import sc.protocol.room.ErrorMessage
21+
import sc.protocol.room.GamePaused
22+
import sc.protocol.room.MementoMessage
23+
import sc.protocol.room.ObservableRoomMessage
2024
import sc.server.client.MessageListener
2125
import sc.server.client.PlayerListener
2226
import sc.server.gaming.GameRoom
2327
import sc.server.helpers.TestTeam
2428
import sc.server.plugins.TestGame
2529
import sc.server.plugins.TestMove
2630
import sc.server.plugins.TestPlugin
31+
import sc.shared.GameResult
2732
import sc.shared.SlotDescriptor
2833
import kotlin.time.Duration
2934
import kotlin.time.ExperimentalTime
@@ -92,15 +97,15 @@ class LobbyRequestTest: WordSpec({
9297
await { room.isPauseRequested shouldBe false }
9398
val game = room.game as TestGame
9499
game.isPaused shouldBe false
100+
await("game started") { game.activePlayer?.color shouldBe TestTeam.RED }
95101
withClue("Processes moves") {
96-
game.activePlayer?.color shouldBe TestTeam.RED
97-
// TODO occasional failure
98102
playerListeners[0].waitForMessage(MoveRequest::class)
99103
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
102106
playerListeners[1].waitForMessage(MoveRequest::class)
103107
players[1].sendMessageToRoom(roomId, TestMove(2))
108+
await { game.activePlayer?.color shouldBe TestTeam.RED }
104109
await { game.currentState.state shouldBe 2 }
105110
}
106111

@@ -116,8 +121,8 @@ class LobbyRequestTest: WordSpec({
116121
}
117122
"a game is prepared with descriptors" should {
118123
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),
121126
)
122127
val prepared = prepareGame(PrepareGameRequest(TestPlugin.TEST_PLUGIN_UUID, descriptors, pause = false))
123128
val room = lobby.findRoom(prepared.roomId)
@@ -133,16 +138,39 @@ class LobbyRequestTest: WordSpec({
133138
slot.isReserved shouldBe descriptor.reserved
134139
}
135140
}
136-
players[0].joinGameRoom(prepared.roomId)
141+
players[1].joinGameRoom(prepared.roomId)
137142
"join player into nonreserved slot" {
138143
await { room.clients shouldHaveSize 1 }
139144
room.slots[0].isEmpty shouldBe true
140145
room.slots[0].isFree shouldBe false
141146
room.slots[1].isEmpty shouldBe false
142147
}
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+
}
146174
}
147175
}
148176
}

0 commit comments

Comments
 (0)