Repository navigation
Add coverage for health-server guards, db readiness deadlines, and lag histogram buckets - #1445
Merged
Merged
Conversation
…ore Fastify is co Closes Vatix-Protocol#1310
…r code so a hung Closes Vatix-Protocol#1315
… boundaries and a Closes Vatix-Protocol#1316
…able so /ready te Closes Vatix-Protocol#1317
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add coverage for health-server guards, db readiness deadlines, and lag histogram buckets
What was solved
#1310 — Workers health server: validate the port before Fastify is constructed and cover the failure path
Extend the workers health-server test suite to explicitly cover the invalid-port guard (negative and non-finite ports throwing before Fastify is constructed), the port-0 ephemeral-listen path with a GET /live 200 assertion, and the listen-failure path asserting a structured error log containing the port and a rethrow. Only test code is added; the production module is left unchanged unless a small adjustment is needed to make the failure path observable.
Addressed:
#1315 — dbReadiness: add a timeout and a stable error code so a hung Postgres cannot stall /ready
Add a bounded deadline and stable error codes to checkDbReadiness in src/services/dbReadiness.ts: race $queryRaw against a 2000ms (overridable) timer, reject with 'db: DEPENDENCY_TIMEOUT' (code DEPENDENCY_TIMEOUT) on timeout and 'db: DEPENDENCY_UNAVAILABLE' (code DEPENDENCY_UNAVAILABLE, cause preserved) on other failures, clearing the timer in finally. Extend src/services/dbReadiness.test.ts with a never-resolving fake prisma (timeout code + bounded settle) and a rejecting fake prisma (unavailable code, no driver message leak).
Addressed:
#1316 — lag-metrics: expose the lag histogram bucket boundaries and assert the shed-threshold straddle
Export DEFAULT_SHED_THRESHOLD = 500 from src/services/lag-metrics.ts, reference it in the JSDoc, and add tests in src/services/lag-metrics.test.ts asserting LAG_HISTOGRAM_BUCKETS is strictly ascending, contains DEFAULT_SHED_THRESHOLD, and that the registered vatix_settlement_lag histogram exposes a le="500" bucket with non-zero count after setCurrentLag(DEFAULT_SHED_THRESHOLD), using resetMetrics() in beforeEach.
Addressed:
#1317 — dbReadiness: make the readiness check injectable so /ready tests do not need a live Postgres
Make checkDbReadiness injectable by accepting an optional client (Pick<PrismaClient, '$queryRaw'>) and timeoutMs, defaulting to getPrismaClient(), so unit tests can simulate resolve/reject/never-settle without a live Postgres while production callers in ready-deps.ts remain unchanged.
Addressed:
Changes
apps/workers/src/health-server.test.ts(modify)src/services/dbReadiness.ts(modify)src/services/dbReadiness.test.ts(modify)src/services/lag-metrics.ts(modify)src/services/lag-metrics.test.ts(modify)src/api/deps/ready-deps.ts(modify)Approach
Issues
Closes #1310
Closes #1315
Closes #1316
Closes #1317