Skip to content

Commit bfe52a4

Browse files
committed
test(server/RequestTest): fix sporadic failures
1 parent d7777de commit bfe52a4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

server/test/sc/server/network/RequestTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import sc.framework.plugins.AbstractGame
99
import sc.framework.plugins.protocol.MoveRequest
1010
import sc.networking.clients.LobbyClient
1111
import sc.protocol.requests.*
12+
import sc.protocol.room.ErrorMessage
1213
import sc.server.Configuration
1314
import sc.server.client.PlayerListener
1415
import sc.server.client.TestLobbyClientListener
@@ -166,6 +167,8 @@ class RequestTest: RealServerTest() {
166167
// Second player sends Move with value 42
167168
player2.sendMessageToRoom(room.id, TestMove(42));
168169
Thread.sleep(100);
170+
TestHelper.waitUntilTrue({ listener.newStateReceived }, 2000)
171+
listener.newStateReceived = false
169172

170173
// Request a move
171174
admin.send(StepRequest(room.id))
@@ -177,15 +180,15 @@ class RequestTest: RealServerTest() {
177180
p1Listener.waitForMessage(MoveRequest::class)
178181

179182
p1Listener.clearMessages() shouldBe 0
183+
p2Listener.clearMessages() shouldBe 0
180184
// Second player sends Move not being his turn
181185
player2.sendMessageToRoom(room.id, TestMove(73))
182-
// TODO this still fails sporadically
183-
TestHelper.waitUntilTrue({ listener.newStateReceived }, 1000)
184-
listener.newStateReceived = false
186+
p2Listener.waitForMessage(ErrorMessage::class)
185187

186188
// There should not come another request
187189
Thread.sleep(500)
188190
p1Listener.clearMessages() shouldBe 0
191+
p2Listener.clearMessages() shouldBe 0
189192
// should not result in a new game state
190193
assertFalse(listener.newStateReceived)
191194

@@ -201,8 +204,8 @@ class RequestTest: RealServerTest() {
201204
val listener = TestLobbyClientListener()
202205
player1.addListener(listener)
203206

204-
await("Lobby creates a room") {
205-
lobby.games.isNotEmpty() && listener.gameJoinedReceived && listener.roomId != null
207+
await("Lobby creates a room and Game starts") {
208+
lobby.games.isNotEmpty() && lobby.games.single().status == GameRoom.GameStatus.ACTIVE
206209
}
207210

208211
player1.send(CancelRequest(listener.roomId))

0 commit comments

Comments
 (0)