feat(health): probe + classify engine on a 60s cron
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
19
tests/health/checker.test.js
Normal file
19
tests/health/checker.test.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { classify, checkAll } from '../../lib/health/checker.js';
|
||||
|
||||
describe('health classify', () => {
|
||||
it('ok when reachable and fast', () => expect(classify({ ok: true, latency: 120 }).status).toBe('ok'));
|
||||
it('warn when reachable but slow', () => expect(classify({ ok: true, latency: 4000 }).status).toBe('warn'));
|
||||
it('warn on non-2xx/3xx reachable', () => expect(classify({ ok: false, reachable: true, latency: 50 }).status).toBe('warn'));
|
||||
it('down when unreachable', () => expect(classify({ ok: false, reachable: false, error: 'ECONN' }).status).toBe('down'));
|
||||
});
|
||||
|
||||
describe('checkAll', () => {
|
||||
it('probes each service and returns a status per id', async () => {
|
||||
const probe = vi.fn().mockResolvedValue({ ok: true, latency: 30 });
|
||||
const svcs = [{ id: 'a', url: 'http://x' }, { id: 'b', url: 'http://y' }];
|
||||
const out = await checkAll(svcs, probe);
|
||||
expect(out.map(o => o.service_id).sort()).toEqual(['a', 'b']);
|
||||
expect(out.every(o => o.status === 'ok')).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user