컴퓨터 방 자동 정리 + 게스트 계정 삭제(로그아웃·하루 미접속) + 테스트 10분→1분
- 방 화면을 벗어나면(홈·규칙) detach: 자리·접속 상태는 유지, 방 접속 수에서 빠짐 - 컴퓨터가 있는 방: 사람이 모두 [방 나가기]하면 바로 닫고, 아무도 안 보면 대기실·끝난 방 1분, 게임 중 30분 뒤 정리 - 게스트 로그아웃 = 계정 삭제(자리·전적·세션·소켓), 사이트를 닫고 24시간 지난 게스트도 1분 주기로 삭제 - users.last_seen_at을 요청·소켓 종료 때 갱신(이전엔 갱신 안 됨), 003 마이그레이션에서 기존 게스트 시계 초기화 - 테스트: 무작위 대국 시드를 playoutSeeds()로 평소 1/10, test:full은 전부. bun test --parallel=4, 테스트 서버 종료 대기 1s→50ms Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -248,6 +248,91 @@ describe('playing with bots', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('practice rooms close once nobody is there', () => {
|
||||
function finishedPractice() {
|
||||
const h = harness();
|
||||
const room = h.manager.createPractice('A', 'omok') as Room;
|
||||
rooms.push(room);
|
||||
const a = h.conn('A');
|
||||
room.join(a, 'player');
|
||||
expect(room.start('A')).toBeNull();
|
||||
room.act('A', 1, { type: 'resign' });
|
||||
expect(room.status).toBe('finished');
|
||||
return { ...h, room, a };
|
||||
}
|
||||
|
||||
test('leaving on purpose (only computers left) closes the room right away', () => {
|
||||
const { room, manager, store } = finishedPractice();
|
||||
room.leave('A');
|
||||
expect(manager.get(room.code)).toBeUndefined();
|
||||
expect(store.openRooms()).toHaveLength(0);
|
||||
expect(manager.activeRoomFor('A')).toBeNull();
|
||||
});
|
||||
|
||||
test('leaving mid-game also closes it', () => {
|
||||
const h = harness();
|
||||
const room = h.manager.createPractice('A', 'omok') as Room;
|
||||
rooms.push(room);
|
||||
room.join(h.conn('A'), 'player');
|
||||
room.start('A');
|
||||
room.leave('A');
|
||||
expect(h.manager.get(room.code)).toBeUndefined();
|
||||
});
|
||||
|
||||
test('going to another page (seat kept) or closing the site: closed a minute later by the sweep', () => {
|
||||
const { room, a, manager, clock, conn } = finishedPractice();
|
||||
room.disconnect(a);
|
||||
manager.sweep();
|
||||
expect(manager.get(room.code)).toBe(room); // a refresh reconnects within seconds
|
||||
clock.advance(30_000);
|
||||
room.join(conn('A'), 'player');
|
||||
room.disconnect(room.conns.get('A')!);
|
||||
clock.advance(59_000);
|
||||
manager.sweep();
|
||||
expect(manager.get(room.code)).toBe(room); // the minute counts from the last disconnect
|
||||
clock.advance(1_000);
|
||||
manager.sweep();
|
||||
expect(manager.get(room.code)).toBeUndefined();
|
||||
});
|
||||
|
||||
test('a running practice game with nobody connected waits 30 minutes', () => {
|
||||
const h = harness();
|
||||
const room = h.manager.createPractice('A', 'omok') as Room;
|
||||
rooms.push(room);
|
||||
const a = h.conn('A');
|
||||
room.join(a, 'player');
|
||||
room.configure('A', { options: { ...(room.config.options as object), colorAssignment: 'hostBlack' } });
|
||||
room.start('A');
|
||||
room.disconnect(a);
|
||||
h.clock.advance(29 * 60_000);
|
||||
h.manager.sweep();
|
||||
expect(h.manager.get(room.code)).toBe(room);
|
||||
h.clock.advance(60_000);
|
||||
h.manager.sweep();
|
||||
expect(h.manager.get(room.code)).toBeUndefined();
|
||||
});
|
||||
|
||||
test('rooms without computers keep the old timeouts; someone still connected keeps any room', () => {
|
||||
const h = harness();
|
||||
const room = h.create('A');
|
||||
const a = h.conn('A');
|
||||
room.join(a, 'player');
|
||||
room.join(h.conn('B'), 'player');
|
||||
room.leave('B');
|
||||
expect(h.manager.get(room.code)).toBe(room);
|
||||
const practice = h.manager.createPractice('C', 'omok') as Room;
|
||||
rooms.push(practice);
|
||||
practice.join(h.conn('C'), 'player');
|
||||
h.clock.advance(5 * 60_000);
|
||||
h.manager.sweep();
|
||||
expect(h.manager.get(practice.code)).toBe(practice);
|
||||
room.disconnect(a);
|
||||
h.clock.advance(5 * 60_000);
|
||||
h.manager.sweep();
|
||||
expect(h.manager.get(room.code)).toBe(room); // empty lobby: 10 minutes
|
||||
});
|
||||
});
|
||||
|
||||
describe('restore after restart', () => {
|
||||
test('bots stay seated, have no reconnect grace, and the driver re-plans their move', () => {
|
||||
const { manager, conn, store, clock, users } = harness();
|
||||
|
||||
Reference in New Issue
Block a user