Handle status fanout rejections (Refs #66)

This commit is contained in:
2026-10-09 12:33:15 -04:00
parent ff589afe5e
commit 96d21d0514
4 changed files with 90 additions and 2 deletions
+32
View File
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { newFixture, type Fixture } from '../helpers/fixture.js';
import { STATUS_REFRESH_MS } from '../../src/lib/server-freshness.js';
vi.mock('../../src/lib/server/pipeline/sweep.js', () => ({ sweep: vi.fn() }));
vi.mock('../../src/lib/server/pipeline/beta-runner.js', () => ({ betaTick: vi.fn() }));
@@ -33,6 +34,37 @@ async function setup() {
}
describe('independent provisioning scheduling', () => {
it.each(['startup', 'scheduled'] as const)('logs a failed %s status snapshot and retries on the next interval', async phase => {
const s = await setup();
const { MonitoringSnapshot } = await import('../../src/lib/server/fleet/monitoring-snapshot.js');
const refresh = vi.spyOn(MonitoringSnapshot.prototype, 'refresh');
const log = vi.spyOn(console, 'error').mockImplementation(() => {});
const failure = new Error('database or disk is full');
vi.useFakeTimers();
try {
if (phase === 'scheduled') {
s.startWorker();
await vi.advanceTimersByTimeAsync(0);
refresh.mockClear();
}
refresh.mockImplementationOnce(() => { throw failure; });
if (phase === 'startup') s.startWorker();
await vi.advanceTimersByTimeAsync(phase === 'startup' ? 0 : STATUS_REFRESH_MS);
expect(refresh).toHaveBeenCalledTimes(1);
expect(log).toHaveBeenCalledExactlyOnceWith('[worker] status fanout error:', failure);
await vi.advanceTimersByTimeAsync(STATUS_REFRESH_MS);
expect(refresh).toHaveBeenCalledTimes(2);
expect(log).toHaveBeenCalledTimes(1);
} finally {
s.stopWorker(); s.background.resolve();
await vi.advanceTimersByTimeAsync(0);
vi.useRealTimers();
refresh.mockRestore(); log.mockRestore();
await vi.waitFor(() => expect(s.workerActivity()).toEqual([]));
}
});
it('collects match chat on worker ticks without overlapping a slow collection', async () => {
const s = await setup();
const { collectFleetChat } = await import('../../src/lib/server/fleet/chat.js');