quality / commitlint (push) Skipped
CD / update-wiki (push) Failing after 8s
quality / changes (push) Successful in 5s
quality / docker-check (push) Skipped
quality / web (push) Successful in 50s
quality / api (push) Successful in 41s
CD / quality (push) Successful in 1m40s
CD / publish (push) Successful in 1m33s
- Introduced origin health check routes and integrated them into the application. - Updated health check configuration to include success recovery thresholds. - Expanded error handling with new error codes for health check failures. - Added new service routes for managing health checks, including creation and listing. - Improved health check service logic to track consecutive successes and failures. This commit enhances the health check capabilities, providing better monitoring and management of service health.
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { nextHealthState } from "../src/services/health/state-machine.js";
|
|
|
|
const thresholds = {
|
|
degradedFailures: 1,
|
|
downFailures: 2,
|
|
successRecoveries: 2,
|
|
latencyWarnMs: 1000,
|
|
};
|
|
|
|
describe("health state machine", () => {
|
|
it("first success from unknown is healthy immediately", () => {
|
|
const next = nextHealthState(true, 20, null, thresholds);
|
|
expect(next.legacy).toBe("up");
|
|
expect(next.node).toBe("healthy");
|
|
});
|
|
|
|
it("recovery from down goes checking until consecutive successes", () => {
|
|
const first = nextHealthState(
|
|
true,
|
|
10,
|
|
{ status: "down", consecutive_failures: 3, consecutive_successes: 0 },
|
|
thresholds,
|
|
);
|
|
expect(first.node).toBe("checking");
|
|
expect(first.legacy).toBe("unknown");
|
|
const second = nextHealthState(
|
|
true,
|
|
10,
|
|
{
|
|
status: "checking",
|
|
consecutive_failures: 0,
|
|
consecutive_successes: first.successes,
|
|
},
|
|
thresholds,
|
|
);
|
|
expect(second.node).toBe("healthy");
|
|
expect(second.legacy).toBe("up");
|
|
});
|
|
|
|
it("two failures mark unhealthy", () => {
|
|
const first = nextHealthState(
|
|
false,
|
|
5,
|
|
{ status: "up", consecutive_failures: 0, consecutive_successes: 1 },
|
|
thresholds,
|
|
);
|
|
expect(first.node).toBe("degraded");
|
|
const second = nextHealthState(
|
|
false,
|
|
5,
|
|
{
|
|
status: "degraded",
|
|
consecutive_failures: first.failures,
|
|
consecutive_successes: 0,
|
|
},
|
|
thresholds,
|
|
);
|
|
expect(second.node).toBe("unhealthy");
|
|
expect(second.legacy).toBe("down");
|
|
});
|
|
});
|