Show fresh player capacity on Fleet cards
This commit is contained in:
@@ -86,6 +86,33 @@ function queueEvent(type: string, data: object) {
|
||||
}
|
||||
|
||||
describe('animation-frame stream batching', () => {
|
||||
it('replaces snapshot capacity with live values and honors explicit unavailable samples', async () => {
|
||||
const at = new Date(epoch).toISOString();
|
||||
snapshot.servers = [server(epoch, { capacity: 4, capacity_observed_at: at })];
|
||||
const { fleetServers } = await setup();
|
||||
expect(get(fleetServers)[0]).toMatchObject({ capacity: 4, capacity_observed_at: at });
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
emit(epoch + 1000, [status(epoch + 1000, { capacity: 8, capacityObservedAt: new Date(epoch + 1000).toISOString() })]);
|
||||
expect(get(fleetServers)[0].capacity).toBe(8);
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
emit(epoch + 2000, [status(epoch + 2000, { capacity: null, capacityObservedAt: null })]);
|
||||
expect(get(fleetServers)[0]).toMatchObject({ capacity: null, capacity_observed_at: null });
|
||||
});
|
||||
|
||||
it('expires capacity independently of fresh rosters and rejects the previous lifecycle limit', async () => {
|
||||
const at = (offset = 0) => new Date(epoch + offset).toISOString();
|
||||
snapshot.servers = [server(epoch, { capacity: 4, capacity_observed_at: at(-90_000),
|
||||
container_state: 'running', container_checked_at: at() })];
|
||||
const { fleetServers } = await setup();
|
||||
expect(get(fleetServers)[0].capacity).toBe(4);
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
queueEvent('server-telemetry', { serverNow: epoch + 1000, entries: [{ ...gameEvent('heartbeat', 15, 3), receivedAt: at(1000) }] });
|
||||
flushFrame();
|
||||
expect(get(fleetServers)[0]).toMatchObject({ health: 'online', last_players: 3, capacity: null, capacity_observed_at: null });
|
||||
emit(epoch + 1000, [status(epoch + 1000, { capacity: 4, capacityObservedAt: at(), telemetryAfter: at(1) })]);
|
||||
expect(get(fleetServers)[0]).toMatchObject({ capacity: null, capacity_observed_at: null });
|
||||
});
|
||||
|
||||
it('publishes each changed store once for a burst and preserves lifecycle evidence through heartbeats', async () => {
|
||||
const stores = await setup();
|
||||
emit(epoch, [status(epoch), status(epoch, { server: 'two' })]);
|
||||
|
||||
Reference in New Issue
Block a user