zmazanie nedohratych hier z lobby
This commit is contained in:
1 parent
115413a813
commit
3655e06587
2 files changed
+80
-37
No files matched your search
+24
-2
@@ -1,4 +1,5 @@
|
||||
import unittest
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import api
|
||||
|
||||
@@ -218,7 +219,7 @@ class SocketLayerCase(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
# --- disconnect & cleanup --------------------------------------------
|
||||
|
||||
async def test_disconnect_marks_player_then_drops_empty_game(self):
|
||||
async def test_disconnect_marks_player_and_schedules_started_game_expiry(self):
|
||||
gid = await self.make_started_game()
|
||||
await api.disconnect("s0")
|
||||
self.assertFalse(api.games[gid].player_by_sid("s0").connected)
|
||||
@@ -227,7 +228,28 @@ class SocketLayerCase(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
for i in range(1, 4):
|
||||
await api.disconnect(f"s{i}")
|
||||
self.assertNotIn(gid, api.games) # everyone gone -> game removed
|
||||
self.assertIn(gid, api.games) # started game stays until its grace period expires
|
||||
self.assertIsNotNone(api.games[gid].abandon_task)
|
||||
|
||||
async def test_abandoned_started_game_expires_after_grace_period(self):
|
||||
gid = "abandoned"
|
||||
game = api.Game(gid, "Abandoned")
|
||||
game.start()
|
||||
game.players = [api.Player(None, f"P{seat}", seat, seat) for seat in range(4)]
|
||||
for player in game.players:
|
||||
player.connected = False
|
||||
api.games[gid] = game
|
||||
|
||||
with (
|
||||
patch.object(api, "GAME_ABANDON_GRACE_SECONDS", 0),
|
||||
patch.object(api.history, "mark_game_ended", new_callable=AsyncMock) as mark_ended,
|
||||
):
|
||||
api._arm_abandon(game)
|
||||
await game.abandon_task
|
||||
|
||||
self.assertNotIn(gid, api.games)
|
||||
mark_ended.assert_awaited_once_with(gid)
|
||||
self.assertEqual(len(self.events("game_ended")), 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user