Show fresh player capacity on Fleet cards
This commit is contained in:
@@ -28,6 +28,30 @@ async function setup() {
|
||||
}
|
||||
|
||||
describe('database fleet and container readiness', () => {
|
||||
it('publishes capacity from accepted monitoring samples and clears it on the next failed check', async () => {
|
||||
const { inspect, rcon, fanoutStatus } = await setup();
|
||||
const { GET } = await import('../../src/routes/api/servers/+server.js');
|
||||
const { subscribe } = await import('../../src/lib/server/pipeline/bus.js');
|
||||
vi.useFakeTimers({ toFake: ['Date'] });
|
||||
const at = Date.parse('2026-10-07T12:00:00Z');
|
||||
vi.setSystemTime(at);
|
||||
inspect.mockResolvedValue({ ok: true, state: 'running' });
|
||||
rcon.mockResolvedValue({ ok: true, endpoint: { host: 'localhost', port: 28960 }, rawReply: 'status',
|
||||
status: { players: 3, capacity: 4, map: 'zombie_theater', gametype: 'zom', roster: [] } });
|
||||
const events: unknown[] = [];
|
||||
const stop = subscribe(event => { if (event.type === 'server-status') events.push(event); });
|
||||
try {
|
||||
await fanoutStatus();
|
||||
expect(events.at(-1)).toMatchObject({ entries: [{ capacity: 4, capacityObservedAt: new Date(at).toISOString() }] });
|
||||
expect((await GET().json()).servers[0]).toMatchObject({ capacity: 4, capacity_observed_at: new Date(at).toISOString() });
|
||||
vi.setSystemTime(at + 30_000);
|
||||
rcon.mockResolvedValue({ ok: false, endpoint: null, reason: 'timeout', detail: 'No reply' });
|
||||
await fanoutStatus();
|
||||
expect(events.at(-1)).toMatchObject({ entries: [{ capacity: null, capacityObservedAt: null }] });
|
||||
expect((await GET().json()).servers[0]).toMatchObject({ capacity: null, capacity_observed_at: null });
|
||||
} finally { stop(); }
|
||||
});
|
||||
|
||||
it('requires two distinct failed monitoring checks, preserves diagnostics, and resets on success', async () => {
|
||||
const { inspect, rcon, fanoutStatus, getServer } = await setup();
|
||||
const { GET } = await import('../../src/routes/api/servers/+server.js');
|
||||
|
||||
Reference in New Issue
Block a user