test(health): isolate lag-only degradation for checks.indexer.status - #1388
Open
Ajibose wants to merge 1 commit into
Open
test(health): isolate lag-only degradation for checks.indexer.status#1388Ajibose wants to merge 1 commit into
Ajibose wants to merge 1 commit into
Conversation
Add an explicitly-isolated test that induces indexerLagDegraded alone (lag > 60s, failure-rate counters healthy) and asserts checks.indexer.status reflects it as "degraded", while also asserting eventsFailed/indexerDegraded stay healthy so the test can't pass on a failure-rate coincidence. The prior lag test relied on beforeEach defaults implicitly rather than asserting isolation explicitly. Closes LabsCrypt#1294
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.
Closes #1294
Summary
Audit issue #1294 asked for a test that isolates lag-only indexer
degradation and asserts the granular
checks.indexer.statusfieldreflects it (matching the top-level
status), per the mismatchdescribed in UX Refinement #34.
Honest status of the underlying bug: it was already fixed by prior
work — PR #1375 / commit
99a79c4(fix: report indexer lag in checks.indexer.status breakdown, closing #1236) changedchecks.indexer.statusinbackend/src/routes/health.routes.tsfrom:to:
That same PR also added a test (
'returns 503 when DB is up, indexer enabled, and lag exceeds 60 s') that sets lag = 120s and assertschecks.indexer.status === 'degraded'. So functionally the coveragegap the audit flagged is mostly closed already — but that test relies
implicitly on
beforeEach's default event counters (degraded: false,eventsFailed: 0) rather than explicitly asserting them in the testbody, so it doesn't visibly prove failure-rate degradation was not a
contributing factor. This PR closes that remaining ambiguity with a
new, explicitly-isolated test rather than a near-duplicate.
I verified this by:
npm run test:unit) — all 40 files/ 316 tests pass, including the existing lag test.
checks.indexer.statusline to thepre-fix: report indexer lag in checks.indexer.status breakdown (#1236) #1375 buggy version and re-running
tests/health.test.ts— boththe existing lag test and the new test correctly failed
(
expected 'ok' to be 'degraded'), confirming the new test wouldhave caught this regression had it not already been fixed.
again.
Changes
backend/tests/health.test.ts: added one new test,'returns checks.indexer.status "degraded" for lag-only degradation, with failure-rate signals asserted healthy (#1294)', placed afterthe existing lag-exceeds-threshold test. It:
STREAM_CONTRACT_ID(indexer enabled) and indexer state lagto 120s (
makeState(120), > the 60s threshold).sorobanEventWorker.getEventCounters()to returnhealthy failure-rate signals (
eventsFailed: 0,degraded: false,non-zero
eventsProcessed) instead of relying onbeforeEachdefaults implicitly.
res.status === 503andres.body.status === 'degraded'.res.body.eventsFailed === 0andres.body.indexerDegraded === false— proving failure-ratedegradation was NOT a contributing factor.
res.body.checks.indexer.status === 'degraded',checks.indexer.enabled === true,checks.indexer.lagSeconds > 60, andchecks.database.status === 'ok'— proving lag alone drove thegranular breakdown to "degraded".
No changes were needed in
backend/src/routes/health.routes.ts— thechecks.indexer.statuscomputation already correctly ORsindexerFailureDegradedandindexerLagDegraded.How to test
cd backend npm install npx prisma generate npm run test:unitAll 40 test files / 316 tests pass.
tests/health.test.tsnow has 8tests (was 7).
To see the new test actually catch a regression, revert line 166 of
backend/src/routes/health.routes.tstostatus: !indexerEnabled ? 'disabled' : indexerFailureDegraded ? 'degraded' : 'ok',and re-run
npx vitest run tests/health.test.ts— both the existinglag test and the new test fail.