Align watchdog tests with supplementary RCON polling

This commit is contained in:
2026-10-07 16:01:02 -04:00
parent c36037b03a
commit 8229a23941
+11 -6
View File
@@ -149,25 +149,30 @@ describe('Watchdog detection and ownership', () => {
expect(rcon.rconStatusResult).toHaveBeenCalledTimes(3);
});
it('uses fresh telemetry alongside the polled container and waits for polled RCON when telemetry expires', async () => {
it.each([0, 4])('uses fresh telemetry with %i players without extra Watchdog probes and waits for polled RCON when telemetry expires', async players => {
const { saveTelemetry } = await import('../../src/lib/server/fleet/telemetry.js');
saveTelemetry({ ...gameEvent('heartbeat', 17, 4, server), receivedAt: new Date().toISOString() });
vi.mocked(rcon.rconStatusResult).mockResolvedValue(missingRcon);
saveTelemetry({ ...gameEvent('heartbeat', 17, players, server), receivedAt: new Date().toISOString() });
// Status polling supplements occupied rosters with pings; Watchdog adds no probes.
const supplementaryProbes = players > 0 ? 1 : 0;
await pollStatus();
expect(rcon.rconStatusResult).toHaveBeenCalledTimes(supplementaryProbes);
await watchdog.watchdogTick();
expect(incidents()).toEqual([]);
expect(rcon.rconStatusResult).not.toHaveBeenCalled();
expect(rcon.rconStatusResult).toHaveBeenCalledTimes(supplementaryProbes);
advance(watchdog.WATCHDOG_SCAN_MS);
await watchdog.watchdogTick();
expect(incidents()).toEqual([]);
expect(rcon.rconStatusResult).not.toHaveBeenCalled();
vi.mocked(rcon.rconStatusResult).mockResolvedValue(missingRcon);
expect(rcon.rconStatusResult).toHaveBeenCalledTimes(supplementaryProbes);
advance(30_001);
await pollStatus();
expect(rcon.rconStatusResult).toHaveBeenCalledTimes(supplementaryProbes + 1);
advance(30_000);
database.db().prepare("DELETE FROM settings WHERE key='watchdog_last_scan'").run();
await watchdog.watchdogTick();
expect(onlyIncident()).toMatchObject({ failures: 1, state: 'open' });
expect(rcon.rconStatusResult).toHaveBeenCalledTimes(1);
expect(rcon.rconStatusResult).toHaveBeenCalledTimes(supplementaryProbes + 1);
expect(operations()).toEqual([]);
});
it('starts a new failure window for a replacement registration', async () => {