Repository navigation
Conversation
…ttle-cards#1325) Merge check-game-state-for-win and check-game-state-for-win-sync into one synchronous checkGameStateForWin with no side effects. The move and ai-move endpoints now record the end of a game (status, winner, match) through a new finishGame helper. Co-authored-by: Arthur Amorim Ruschel <aruschel@usp.br> Co-authored-by: Gabriel Meirelles Cury <g.cury@usp.br>
Comment on lines
+34
to
+41
| if (game.status === GameStatus.STARTED) { | ||
| await Game.updateOne({ id: game.id }).set(gameUpdates); | ||
| } | ||
|
|
||
| const currentMatch = await sails.helpers.addGameToMatch({ | ||
| ...game, | ||
| ...gameUpdates, | ||
| }); |
There was a problem hiding this comment.
If addGameToMatch fails after Game.updateOne succeeds, the game stays finished without being added to its match. Retrying the move is rejected because the game is finished. Previously, loading its winning state retried addGameToMatch; now getGameMatch returns null when the link is missing, so the ranked result stays uncounted.
Make the writes succeed together, or keep a reliable retry path for the missing match write.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue number
Relevant issue number
check-game-state-for-winandcheck-game-state-for-win-sync#1325Please check the following
Please describe additional details for testing this change
What changed
check-game-state-for-win-sync.jsis merged intocheck-game-state-for-win.js, which is now the single synchronouscheckGameStateForWin()with no side effects. The issue calls thesecheckWinGameState()/checkWinGameStateSync(); I kept the existing shorter helper name.moveandai-moveendpoints. After saving the new game state, they check for a win and, only if the game ended, call a newfinishGamehelper (marks the game finished, sets the winner, adds it to its match). It's a helper so both endpoints share it.createSocketEventsno longer writes anything. The socket event still needs the match for the game-over dialog, so:finishGamethroughpublishGameState(new optionalcurrentMatchinput);getGameMatchhelper.addGameToMatchnow reuses it instead of duplicating that lookup.createSocketEventsis now acountPasseshelper, since the endpoints need it too.tests/unit/fixtures/gameStates/points.js: the fixture game was FINISHED with no winner and relied oncreateSocketEventsto fill it in; it now has its winner recorded.Testing
npm run lint, client unit tests and sails unit tests pass.tests/unit/specs/sails/game-over.spec.jscovers: winning moves record the winner (casual) and add the game to its match (ranked), a non-winning move leaves the game in progress, andcreateSocketEventson a winning state no longer touches the database (this last test fails onmain).Fix the missing retry path for failed match writes before merging.
Findings
Summary
Makes
checkGameStateForWinsynchronous and moves end-of-game writes intofinishGame.Reviews (1) · Last reviewed commit: "refactor(game-states): make checkGameSta..." · Reviewed by Greptile