Skip to content

Fix Cosmos DB health check: ensure query is actually executed#4942

Draft
rudolphjacksonm with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-code-for-review-comment
Draft

Fix Cosmos DB health check: ensure query is actually executed#4942
rudolphjacksonm with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-code-for-review-comment

Conversation

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Resolves #4926

What is being addressed

container.query_items("SELECT TOP 1 * FROM c") returns a lazy iterator and never executes the query, causing the health check to falsely report OK even when Cosmos DB is down or inaccessible.

How is this addressed

  • health_checker.py: Use async for with break to force execution of the query, confirming connectivity:
    async for _ in container.query_items("SELECT TOP 1 * FROM c", max_item_count=1):
        break
  • test_health_checker.py:
    • Fixed test_get_state_store_status_responding to patch Database.get_container_proxy (instead of ContainerProxy.query_items) and return a container mock with a real async iterator
    • Added AsyncIteratorWithError helper to simulate exceptions raised during iteration
    • Added test_get_state_store_status_cosmos_http_error and test_get_state_store_status_service_request_error to cover error paths that only trigger during actual query execution
    • Moved helper classes (AsyncIterator, AsyncIteratorWithError) to top of file
  • Updated CHANGELOG.md and bumped API version to 0.25.17

Copilot AI changed the title [WIP] Fix code as per review comment Fix Cosmos DB health check: ensure query is actually executed Jun 30, 2026
Copilot AI requested a review from rudolphjacksonm June 30, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Health check can falsely return OK even if Cosmos is down or inaccessible

2 participants