Skip to content

Commit

Permalink
Issue/#407 unranked games not being scored (#408)
Browse files Browse the repository at this point in the history
* Added failing test for unranked games not being scored

* Remove validity check in on_game_end

* Pls coveralls...
  • Loading branch information
Askaholic authored and Rackover committed Mar 8, 2019
1 parent 72ec013 commit 75f0093
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
5 changes: 1 addition & 4 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,6 @@ async def on_game_end(self):
elif self.state == GameState.LIVE:
self._logger.info("Game finished normally")

if self.validity is not ValidityState.VALID:
return

if self.desyncs > 20:
await self.mark_invalid(ValidityState.TOO_MANY_DESYNCS)
return
Expand All @@ -453,7 +450,7 @@ async def on_game_end(self):
await self.persist_results()
await self.rate_game()
await self._process_pending_army_stats()
except Exception as e:
except Exception as e: # pragma: no cover
self._logger.exception("Error during game end: %s", e)
finally:
self.state = GameState.ENDED
Expand Down
25 changes: 24 additions & 1 deletion tests/unit_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ async def test_uneven_teams_not_rated(game):
await game.on_game_end()
assert game.validity == ValidityState.UNEVEN_TEAMS_NOT_RANKED


async def test_single_team_not_rated(game):
n_players = 4
game.state = GameState.LOBBY
Expand All @@ -160,6 +161,7 @@ async def test_single_team_not_rated(game):

assert game.validity is ValidityState.UNEVEN_TEAMS_NOT_RANKED


def test_set_player_option(game, players, mock_game_connection):
game.state = GameState.LOBBY
mock_game_connection.player = players.hosting
Expand All @@ -176,6 +178,7 @@ def test_set_player_option(game, players, mock_game_connection):
def test_invalid_get_player_option_key(game: Game, players):
assert game.get_player_option(players.hosting.id, -1) is None


def test_add_game_connection(game: Game, players, mock_game_connection):
game.state = GameState.LOBBY
mock_game_connection.player = players.hosting
Expand Down Expand Up @@ -223,6 +226,7 @@ async def test_game_end_when_no_more_connections(game: Game, mock_game_connectio

game.on_game_end.assert_any_call()


@patch('server.games.game.db.engine') # FIXME
async def test_game_sim_ends_when_no_more_connections(game: Game, players):
await game.clear_data()
Expand All @@ -237,6 +241,7 @@ async def test_game_sim_ends_when_no_more_connections(game: Game, players):
await game.remove_game_connection(join_conn)
assert game.ended


@patch('server.games.game.db.engine') # FIXME
async def test_game_sim_ends_when_connections_ended_sim(game: Game, players):
await game.clear_data()
Expand All @@ -252,13 +257,15 @@ async def test_game_sim_ends_when_connections_ended_sim(game: Game, players):
await game.check_sim_end()
assert game.ended


async def test_game_marked_dirty_when_timed_out(game: Game):
game.state = GameState.INITIALIZING
game.sleep = CoroMock()
await game.timeout_game()
assert game.state == GameState.ENDED
assert game in game.game_service.dirty_games


async def test_clear_slot(game: Game, mock_game_connection: GameConnection):
game.state = GameState.LOBBY
players = [
Expand All @@ -268,7 +275,6 @@ async def test_clear_slot(game: Game, mock_game_connection: GameConnection):
add_connected_players(game, players)
game.set_ai_option('rush', 'StartSpot', 3)


game.clear_slot(0)
game.clear_slot(3)

Expand Down Expand Up @@ -569,6 +575,23 @@ async def test_persist_results_called_with_two_players(game):
assert game.get_army_score(1) == 5


async def test_persist_results_called_for_unranked(game):
await game.clear_data()
game.state = GameState.LOBBY
add_players(game, 2)
await game.launch()
game.validity = ValidityState.BAD_UNIT_RESTRICTIONS
assert len(game.players) == 2
await game.add_result(0, 1, 'victory', 5)
await game.on_game_end()

assert game.get_army_score(1) == 5
assert len(game.players) == 2

await game.load_results()
assert game.get_army_score(1) == 5


async def test_get_army_score_conflicting_results_clear_winner(game):
game.state = GameState.LOBBY
add_players(game, 3, team=2)
Expand Down

0 comments on commit 75f0093

Please sign in to comment.