Show resetting state after game end

This commit is contained in:
2026-09-19 22:50:17 -04:00
parent f975911204
commit 5985959882
7 changed files with 88 additions and 9 deletions
+24
View File
@@ -30,6 +30,30 @@ async function setup() {
}
describe('database fleet and container readiness', () => {
it('keeps game_end through occupied polls until game_start or an empty lobby', async () => {
const { inspect, rcon, fanoutStatus, getServer } = await setup();
inspect.mockResolvedValue({ ok: true, state: 'running' });
const reply = (players: number) => ({ ok: true as const, endpoint: { host: 'localhost', port: 28960 }, rawReply: 'status',
status: { players, map: 'zombie_theater', gametype: 'zom', roster: [] } });
rcon.mockResolvedValue(reply(1));
await postTelemetry(gameEvent('game_start', 0, 1, 'managed'));
await postTelemetry(gameEvent('game_end', 10, 1, 'managed'));
const ended = getServer('managed')?.game_ended_at;
expect(ended).toEqual(expect.any(String));
await postTelemetry(gameEvent('heartbeat', 10, 1, 'managed'));
await fanoutStatus();
expect(getServer('managed')?.game_ended_at).toBe(ended);
await postTelemetry(gameEvent('game_start', 0, 1, 'managed'));
expect(getServer('managed')?.game_ended_at).toBeNull();
await postTelemetry(gameEvent('game_end', 10, 1, 'managed'));
rcon.mockResolvedValue(reply(0));
await fanoutStatus();
expect(getServer('managed')).toMatchObject({ game_started_at: null, game_ended_at: null });
rcon.mockResolvedValue(reply(1));
await fanoutStatus();
expect(getServer('managed')?.game_ended_at).toBeNull();
});
it('waits for game_start telemetry after log initialization and player joins', async () => {
const { inspect, rcon, fanoutStatus, getServer } = await setup();
const { GET } = await import('../../src/routes/api/servers/+server.js');
+21
View File
@@ -65,6 +65,27 @@ async function setup() {
}
describe('Fleet report clock', () => {
it('applies game lifecycle events immediately and clears them after an empty report', async () => {
const { fleetServers } = await setup();
const report = (event: string, time: number) => source.dispatchEvent(new MessageEvent('server-telemetry', {
data: JSON.stringify({ serverNow: time, entries: [{ server: 't5_zombie_theater_1', event,
receivedAt: new Date(time).toISOString(), players: [] }] })
}));
emit(epoch, [status(epoch, { players: 1 })]);
report('game_end', epoch + 1000);
expect(get(fleetServers)[0].game_ended_at).toBe(new Date(epoch + 1000).toISOString());
report('heartbeat', epoch + 2000);
expect(get(fleetServers)[0].game_ended_at).not.toBeNull();
report('game_start', epoch + 3000);
expect(get(fleetServers)[0].game_ended_at).toBeNull();
report('game_end', epoch + 4000);
await vi.advanceTimersByTimeAsync(5000);
emit(epoch + 5000, [status(epoch + 5000)]);
expect(get(fleetServers)[0].game_ended_at).toBeNull();
emit(epoch + 6000, [status(epoch + 6000, { players: 1 })]);
expect(get(fleetServers)[0].game_ended_at).toBeNull();
});
it.each([-2500, 60_000])('keeps fresh HTTP and streamed reports healthy with a browser clock offset of %i ms', async (offset) => {
vi.setSystemTime(epoch + offset);
const { fleetServers, uiNow, refreshFleet } = await setup();