Skip to content

Commit

Permalink
Stop sending game_launch when match is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Aug 4, 2021
1 parent 2776484 commit 07912bc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 62 deletions.
28 changes: 12 additions & 16 deletions server/ladder_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,26 +446,22 @@ def game_options(player: Player) -> GameLaunchOptions:
map_position=game.get_player_option(player.id, "StartSpot")
)

# Tell the host to launch
await host.lobby_connection.launch_game(
game, is_host=True, options=game_options(host)
)
try:
await game.wait_hosted(60)
finally:
# TODO: Once the client supports `match_cancelled`, don't
# send `launch_game` to the client if the host timed out. Until
# then, failing to send `launch_game` will cause the client to
# think it is searching for ladder, even though the server has
# already removed it from the queue.

await asyncio.gather(*[
guest.lobby_connection.launch_game(
game, is_host=False, options=game_options(guest)
)
for guest in all_guests
if guest.lobby_connection is not None
])
await game.wait_hosted(60)

# Tell the guests to launch
await asyncio.gather(*[
guest.lobby_connection.launch_game(
game, is_host=False, options=game_options(guest)
)
for guest in all_guests
if guest.lobby_connection is not None
])
await game.wait_launched(60 + 10 * len(all_guests))

self._logger.debug("Ladder game launched successfully")
except Exception:
if game:
Expand Down
28 changes: 12 additions & 16 deletions tests/integration_tests/test_matchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,11 @@ async def test_game_matchmaking_start_while_matched(lobby_server):
async def test_game_matchmaking_timeout(lobby_server, game_service):
proto1, proto2 = await queue_players_for_matchmaking(lobby_server)

msg1, msg2 = await asyncio.gather(
read_until_command(proto1, "game_launch", timeout=120),
read_until_command(proto2, "game_launch", timeout=120)
)
# LEGACY BEHAVIOUR: The host does not respond with the appropriate GameState
# so the match is cancelled. However, the client does not know how to
# handle `match_cancelled` messages so we still send `game_launch` to
# prevent the client from showing that it is searching when it really isn't.
msg1 = await read_until_command(proto1, "game_launch", timeout=120)
await read_until_command(proto2, "match_cancelled", timeout=120)
await read_until_command(proto1, "match_cancelled", timeout=120)

assert msg1["uid"] == msg2["uid"]
assert msg1["mod"] == "ladder1v1"
assert msg2["mod"] == "ladder1v1"

# Ensure that the game is cleaned up
await read_until_command(
Expand All @@ -150,7 +141,15 @@ async def test_game_matchmaking_timeout(lobby_server, game_service):
)
assert game_service._games == {}

# Player's state is reset once they leave the game
# Player's state is not reset immediately
await proto1.send_message({
"command": "game_matchmaking",
"state": "start",
})
with pytest.raises(asyncio.TimeoutError):
await read_until_command(proto1, "search_info", state="start", timeout=5)

# Player's state is only reset once they leave the game
await proto1.send_message({
"command": "GameState",
"target": "game",
Expand All @@ -159,18 +158,15 @@ async def test_game_matchmaking_timeout(lobby_server, game_service):
await proto1.send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "uef"
})
await read_until_command(proto1, "search_info", state="start", timeout=5)

# And not before they've left the game
# But it is reset for the player who didn't make it into the game
await proto2.send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "uef"
})
with pytest.raises(asyncio.TimeoutError):
await read_until_command(proto2, "search_info", state="start", timeout=5)
await read_until_command(proto2, "search_info", state="start", timeout=5)


@fast_forward(120)
Expand Down
32 changes: 8 additions & 24 deletions tests/integration_tests/test_teammatchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,13 @@ async def test_game_matchmaking_multiqueue_timeout(lobby_server):
await protos[0].send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "cybran",
"queue_name": "ladder1v1"
})
await read_until_command(protos[0], "search_info", state="start")
await asyncio.gather(*[
proto.send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "seraphim",
"queue_name": "tmm2v2"
})
for proto in protos
Expand All @@ -339,6 +337,14 @@ async def test_game_matchmaking_multiqueue_timeout(lobby_server):
# Don't send any GPGNet messages so the match times out
await read_until_command(protos[0], "match_cancelled", timeout=120)

# Player's state is not reset immediately
await protos[0].send_message({
"command": "game_matchmaking",
"state": "start",
})
with pytest.raises(asyncio.TimeoutError):
await read_until_command(protos[1], "search_info", state="start", timeout=5)

# Player's state is reset once they leave the game
await protos[0].send_message({
"command": "GameState",
Expand All @@ -348,7 +354,6 @@ async def test_game_matchmaking_multiqueue_timeout(lobby_server):
await protos[0].send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "uef"
})
await read_until_command(
protos[0],
Expand All @@ -358,15 +363,6 @@ async def test_game_matchmaking_multiqueue_timeout(lobby_server):
timeout=5
)

# And not before they've left the game
await protos[1].send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "uef"
})
with pytest.raises(asyncio.TimeoutError):
await read_until_command(protos[1], "search_info", state="start", timeout=5)


@fast_forward(60)
async def test_game_matchmaking_multiqueue_multimatch(lobby_server):
Expand All @@ -388,7 +384,6 @@ async def test_game_matchmaking_multiqueue_multimatch(lobby_server):
proto.send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "uef",
"queue_name": "ladder1v1"
})
for proto in protos[:2]
Expand All @@ -397,7 +392,6 @@ async def test_game_matchmaking_multiqueue_multimatch(lobby_server):
proto.send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "aeon",
"queue_name": "tmm2v2"
})
for proto in protos
Expand Down Expand Up @@ -451,7 +445,6 @@ async def test_game_matchmaking_timeout(lobby_server):
await protos[0].send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "uef"
})
await read_until_command(
protos[0],
Expand All @@ -461,15 +454,6 @@ async def test_game_matchmaking_timeout(lobby_server):
timeout=5
)

# And not before they've left the game
await protos[1].send_message({
"command": "game_matchmaking",
"state": "start",
"faction": "uef"
})
with pytest.raises(asyncio.TimeoutError):
await read_until_command(protos[1], "search_info", state="start", timeout=5)


@fast_forward(60)
async def test_game_ratings(lobby_server):
Expand Down
9 changes: 3 additions & 6 deletions tests/unit_tests/test_ladder_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ async def test_start_game_1v1(
game = game_service[game_service.game_id_counter]

assert player1.lobby_connection.launch_game.called
# TODO: Once client supports `match_cancelled` change this to `assert not`
assert player2.lobby_connection.launch_game.called
assert isinstance(game, LadderGame)
assert game.rating_type == queue.rating_type
Expand Down Expand Up @@ -169,11 +168,9 @@ async def test_start_game_timeout(
p1.lobby_connection.write.assert_called_once_with({"command": "match_cancelled"})
p2.lobby_connection.write.assert_called_once_with({"command": "match_cancelled"})
assert p1.lobby_connection.launch_game.called
# TODO: Once client supports `match_cancelled` change this to `assert not`
# and uncomment the following lines.
assert p2.lobby_connection.launch_game.called
# assert p1.state is PlayerState.IDLE
# assert p2.state is PlayerState.IDLE
assert not p2.lobby_connection.launch_game.called
assert p1.state is PlayerState.IDLE
assert p2.state is PlayerState.IDLE


@given(
Expand Down

0 comments on commit 07912bc

Please sign in to comment.