room seat cron backstop: expire_lapsed_room_seats sweeps idle mid-game tables — TDD
Phase 6 (final) of the room GATE VIEW + seat-renewal sprint. Cron backstop mirroring delete_stale_my_sea_draws — the lazy _expire_lapsed_seats already frees seats on every room/gate-view access, but a mid-game table nobody reopens past the grace window would keep its stuck seats forever. This command runs the same sweep over every room holding a timestamped FILLED slot. No flags; idempotent. Tests: ExpireLapsedRoomSeatsCommandTest (2) — frees a >2S lapsed seat + flags RENEWAL_DUE; no-op within grace. Full project suite 1590 ITs/UTs green. Code architected by Disco DeDisco <discodedisco@outlook.com> Git commit message Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2995,3 +2995,41 @@ class ExpireLapsedSeatsTest(TestCase):
|
||||
self.room.save()
|
||||
response = self.client.get(reverse("epic:room", args=[self.room.id]))
|
||||
self.assertContains(response, "id_gamer_needed")
|
||||
|
||||
|
||||
class ExpireLapsedRoomSeatsCommandTest(TestCase):
|
||||
"""Cron backstop for rooms nobody reopens — `expire_lapsed_room_seats`
|
||||
runs the same `_expire_lapsed_seats` sweep the lazy view path uses, for
|
||||
mid-game tables left idle past the grace window."""
|
||||
|
||||
def _room_with_filled_slot(self, email, filled_at):
|
||||
owner = User.objects.create(email=email)
|
||||
room = Room.objects.create(
|
||||
name="Cron Room", owner=owner, renewal_period=timedelta(days=7),
|
||||
gate_status=Room.OPEN, table_status=Room.ROLE_SELECT,
|
||||
)
|
||||
slot = room.gate_slots.get(slot_number=1)
|
||||
slot.gamer = owner
|
||||
slot.status = GateSlot.FILLED
|
||||
slot.filled_at = filled_at
|
||||
slot.debited_token_type = Token.FREE
|
||||
slot.save()
|
||||
return room, slot
|
||||
|
||||
def test_command_frees_lapsed_seat_and_sets_renewal_due(self):
|
||||
from django.core.management import call_command
|
||||
room, slot = self._room_with_filled_slot(
|
||||
"lapsed@test.io", timezone.now() - timedelta(days=15))
|
||||
call_command("expire_lapsed_room_seats")
|
||||
slot.refresh_from_db()
|
||||
room.refresh_from_db()
|
||||
self.assertEqual(slot.status, GateSlot.EMPTY)
|
||||
self.assertEqual(room.gate_status, Room.RENEWAL_DUE)
|
||||
|
||||
def test_command_noop_within_grace(self):
|
||||
from django.core.management import call_command
|
||||
room, slot = self._room_with_filled_slot(
|
||||
"ingrace@test.io", timezone.now() - timedelta(days=8))
|
||||
call_command("expire_lapsed_room_seats")
|
||||
slot.refresh_from_db()
|
||||
self.assertEqual(slot.status, GateSlot.FILLED)
|
||||
|
||||
Reference in New Issue
Block a user