#1166 Engineer Integration Test Coverage for the Health Drain Readine… - #1204
Open
veloura-dev wants to merge 1 commit into
Conversation
…rain Readiness Route FIXED
|
@veloura-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
CLOSE #1166
1. Detailed Findings
apps/backend/src/app/api/health/drain/route.tsexposes the readiness endpointGET /api/health/drainfor container orchestrators and load balancers during rolling deployments. It fronts theisDraining()andinFlightCount()state fromapps/backend/src/lib/shutdown-manager.ts. However, no integration test suite existed to verify that HTTP requests to this route properly reflect internal shutdown manager state transitions.apps/backend/src/lib/shutdown-manager.ts, state variables (draining,inFlight,realtimeCleanups) are module-level singletons. In order to run multiple lifecycle integration tests in sequence without module pollution, a state reset mechanism was required.2. Implemented Fix Features
Pre-Drain State Coverage:
GET /api/health/drainreturns HTTP200with{ inFlightCount: 0, draining: false }on an idle server before any drain signal.trackOperation(id)increments theinFlightCountreflected in the GET response while keepingdraining: false.done()callbacks decrementsinFlightCountdynamically back to0prior to draining.Mid-Drain State (In-Flight Operations Active):
drain()immediately transitions the route's response todraining: truewhile preserving the exact count of active in-flight operations./api/health/drainreflect the decreasinginFlightCountin real time (2 → 1 → 0).vi.useFakeTimers()). Confirms that stuck operations that fail to complete within the 30-second window are force-failed via Supabase, clearing the in-flight count (inFlightCount: 0,draining: true).Post-Drain State Coverage:
drain()wheninFlightCount === 0transitions the route directly to{ inFlightCount: 0, draining: true }.{ inFlightCount: 0, draining: true }.registerRealtimeCleanup) are executed during the drain lifecycle.Response Contract & Schema Validation:
200 OK.Content-Typeheader containsapplication/json.inFlightCountasnumber,drainingasboolean).Test Isolation Hook (
_resetState):_resetState()inapps/backend/src/lib/shutdown-manager.tsto cleardraining, emptyinFlight, and resetrealtimeCleanupsbetween test runs.