From 29812861ca5a7e4a99263e52c7dee2f02f1785bd Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 18:06:25 +0000 Subject: [PATCH] test(proxy): cover routed reader recreate race in health_check Adds a RoutingPrismaWrapper regression test so a SELECT 1 routed to the read replica during the reader's planned engine recreate is not alerted, exercising the writer+reader inspection path. --- .../proxy/db/test_prisma_self_heal.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_litellm/proxy/db/test_prisma_self_heal.py b/tests/test_litellm/proxy/db/test_prisma_self_heal.py index 28af01c7402..39e3c774c68 100644 --- a/tests/test_litellm/proxy/db/test_prisma_self_heal.py +++ b/tests/test_litellm/proxy/db/test_prisma_self_heal.py @@ -12,6 +12,7 @@ sys.path.insert( 0, os.path.abspath("../../../..") ) # Adds the parent directory to the system path +from litellm.proxy.db.routing_prisma_wrapper import RoutingPrismaWrapper from litellm.proxy.utils import PrismaClient, ProxyLogging @@ -720,3 +721,33 @@ async def test_health_check_reports_real_outage_with_correct_label( assert kwargs["call_type"] == "health_check" assert "health_check()" in kwargs["traceback_str"] assert "disconnect()" not in kwargs["traceback_str"] + + +@pytest.mark.asyncio +async def test_health_check_not_alerted_when_reader_recreate_in_flight( + mock_proxy_logging, no_backoff_sleep +): + """With a read replica configured, a SELECT 1 routed to the reader that + races the reader's planned engine recreate must not be reported: both the + routed writer and reader wrappers are inspected for an in-flight recreate.""" + client = PrismaClient( + database_url="mock://test", proxy_logging_obj=mock_proxy_logging + ) + reader_holder = PrismaClient( + database_url="mock://test", proxy_logging_obj=mock_proxy_logging + ) + reader = reader_holder.db + client.db = RoutingPrismaWrapper(client.db, reader) + reader.query_raw = AsyncMock( + side_effect=httpx.ConnectError("All connection attempts failed") + ) + + await reader._reconnection_lock.acquire() + try: + with pytest.raises(httpx.ConnectError): + await client.health_check() + finally: + reader._reconnection_lock.release() + + await asyncio.sleep(0) + mock_proxy_logging.failure_handler.assert_not_called()