Fix stale match liveness and stop handling (Refs #136)
CI / checks (push) Successful in 5m15s
CI / checks (push) Successful in 5m15s
This commit is contained in:
@@ -369,6 +369,39 @@ it('refreshes stats during a round without adding rounds or completing the match
|
||||
expect((await matches()).map((match) => match.status)).toEqual(['completed', 'active']);
|
||||
});
|
||||
|
||||
it('refreshes the last report for identical heartbeats without changing participation or completed results', async () => {
|
||||
const { serverMatchHistory } = await import('../../src/lib/server/fleet/match-history.js');
|
||||
await report('game_start');
|
||||
await report('heartbeat', 5, [player(undefined, { kills: 100 })]);
|
||||
const participants = await records();
|
||||
received += 120;
|
||||
await report('heartbeat', 5, [player(undefined, { kills: 100 })]);
|
||||
expect(await matches()).toHaveLength(1);
|
||||
expect(await records()).toEqual(participants);
|
||||
expect(serverMatchHistory(server).matches[0]).toMatchObject({
|
||||
status: 'active',
|
||||
lastReportedAt: '2026-09-18T20:02:02.000Z'
|
||||
});
|
||||
await report('game_end', 5);
|
||||
const completed = serverMatchHistory(server).matches[0];
|
||||
await report('game_end', 5);
|
||||
expect(serverMatchHistory(server).matches[0]).toEqual(completed);
|
||||
});
|
||||
|
||||
it('starts a new match when an identical heartbeat follows an interrupted match', async () => {
|
||||
await report('heartbeat', 5);
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
db()
|
||||
.prepare("UPDATE leaderboard_matches SET status='interrupted', ended_at=last_received_at")
|
||||
.run();
|
||||
const interrupted = (await matches())[0];
|
||||
await report('heartbeat', 5);
|
||||
expect(await matches()).toEqual([
|
||||
interrupted,
|
||||
expect.objectContaining({ status: 'active', highest_round: 5, start_observed: 0 })
|
||||
]);
|
||||
});
|
||||
|
||||
it('persists independent stat high-water marks without adding cumulative snapshots or retries', async () => {
|
||||
await report('game_start');
|
||||
await report('round_change', 1);
|
||||
|
||||
Reference in New Issue
Block a user