Test match timer waits for game_start telemetry
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { newFixture, type Fixture } from '../helpers/fixture.js';
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { gameEvent, postTelemetry } from '../helpers/telemetry.js';
|
||||
|
||||
vi.mock('../../src/lib/server/integrations/komodo.js', () => ({
|
||||
komodoInspectHealthy: vi.fn(), komodoRestart: vi.fn()
|
||||
@@ -27,6 +30,33 @@ async function setup() {
|
||||
}
|
||||
|
||||
describe('database fleet and container readiness', () => {
|
||||
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');
|
||||
const logs = join(fixture.t5, 'managed', 'logs');
|
||||
await mkdir(logs, { recursive: true });
|
||||
await writeFile(join(logs, 'games_sp.log'), '0:00 InitGame:\n0:01 J;123;0;Player\n');
|
||||
inspect.mockResolvedValue({ ok: true, state: 'running' });
|
||||
rcon.mockResolvedValue({ ok: true, endpoint: { host: 'localhost', port: 28960 }, rawReply: 'status',
|
||||
status: { players: 1, map: 'zombie_theater', gametype: 'zom', roster: [] } });
|
||||
await fanoutStatus();
|
||||
expect(getServer('managed')).toMatchObject({ active_since: expect.any(String), game_started_at: null });
|
||||
|
||||
for (const event of ['round_change', 'heartbeat'] as const) {
|
||||
expect((await postTelemetry(gameEvent(event, 1, 1, 'managed'))).status).toBe(200);
|
||||
await fanoutStatus();
|
||||
expect((await (await GET()).json()).servers[0].game_started_at).toBeNull();
|
||||
}
|
||||
|
||||
const response = await postTelemetry(gameEvent('game_start', 0, 1, 'managed'));
|
||||
expect(response.status).toBe(200);
|
||||
const { telemetry } = await response.json();
|
||||
await fanoutStatus();
|
||||
expect((await (await GET()).json()).servers[0]).toMatchObject({
|
||||
game_started_at: telemetry.receivedAt, game_ended_at: null
|
||||
});
|
||||
});
|
||||
|
||||
it('includes the server clock with the health snapshot', async () => {
|
||||
await setup();
|
||||
const { GET } = await import('../../src/routes/api/servers/+server.js');
|
||||
|
||||
Reference in New Issue
Block a user