@@ -97,6 +97,59 @@ def test_get_embedding_function_init_exception():
9797 )
9898
9999
100+ @pytest .mark .asyncio
101+ async def test_try_server_versions ():
102+ # Test successful v1 response
103+ with patch ("httpx.AsyncClient" ) as mock_client :
104+ mock_response = MagicMock ()
105+ mock_response .status_code = 200
106+ mock_client .return_value .__aenter__ .return_value .get .return_value = (
107+ mock_response
108+ )
109+ assert await try_server ("http://localhost:8300" ) is True
110+ mock_client .return_value .__aenter__ .return_value .get .assert_called_once_with (
111+ url = "http://localhost:8300/api/v1/heartbeat"
112+ )
113+
114+ # Test fallback to v2 when v1 fails
115+ with patch ("httpx.AsyncClient" ) as mock_client :
116+ mock_response_v1 = MagicMock ()
117+ mock_response_v1 .status_code = 404
118+ mock_response_v2 = MagicMock ()
119+ mock_response_v2 .status_code = 200
120+ mock_client .return_value .__aenter__ .return_value .get .side_effect = [
121+ mock_response_v1 ,
122+ mock_response_v2 ,
123+ ]
124+ assert await try_server ("http://localhost:8300" ) is True
125+ assert mock_client .return_value .__aenter__ .return_value .get .call_count == 2
126+
127+ # Test both versions fail
128+ with patch ("httpx.AsyncClient" ) as mock_client :
129+ mock_response_v1 = MagicMock ()
130+ mock_response_v1 .status_code = 404
131+ mock_response_v2 = MagicMock ()
132+ mock_response_v2 .status_code = 500
133+ mock_client .return_value .__aenter__ .return_value .get .side_effect = [
134+ mock_response_v1 ,
135+ mock_response_v2 ,
136+ ]
137+ assert await try_server ("http://localhost:8300" ) is False
138+
139+ # Test connection error cases
140+ with patch ("httpx.AsyncClient" ) as mock_client :
141+ mock_client .return_value .__aenter__ .return_value .get .side_effect = (
142+ httpx .ConnectError ("Cannot connect" )
143+ )
144+ assert await try_server ("http://localhost:8300" ) is False
145+
146+ with patch ("httpx.AsyncClient" ) as mock_client :
147+ mock_client .return_value .__aenter__ .return_value .get .side_effect = (
148+ httpx .ConnectTimeout ("Connection timeout" )
149+ )
150+ assert await try_server ("http://localhost:8300" ) is False
151+
152+
100153def test_verify_ef ():
101154 # Mocking AsyncCollection and Config
102155 mock_collection = MagicMock ()
@@ -137,18 +190,10 @@ async def test_try_server_mocked(mock_socket):
137190 with patch ("httpx.AsyncClient" ) as mock_client :
138191 mock_response = MagicMock ()
139192 mock_response .status_code = 200
140- mock_response .content = b'{"info":{"title": "Chroma"}}'
141193 mock_client .return_value .__aenter__ .return_value .get .return_value = (
142194 mock_response
143195 )
144196 assert await try_server ("http://localhost:8000" ) is True
145- with patch ("httpx.AsyncClient" ) as mock_client :
146- mock_response = MagicMock ()
147- mock_response .status_code = 404
148- mock_client .return_value .__aenter__ .return_value .get .return_value = (
149- mock_response
150- )
151- assert await try_server ("http://localhost:8000" ) is False
152197
153198 # Mocking httpx.AsyncClient to raise a ConnectError
154199 with patch ("httpx.AsyncClient" ) as mock_client :
@@ -157,15 +202,6 @@ async def test_try_server_mocked(mock_socket):
157202 )
158203 assert await try_server ("http://localhost:8000" ) is False
159204
160- with patch ("httpx.AsyncClient" ) as mock_client :
161- mock_response = MagicMock ()
162- mock_response .status_code = 200
163- mock_response .content = b'{"info":{"title": "Dummy"}}'
164- mock_client .return_value .__aenter__ .return_value .get .return_value = (
165- mock_response
166- )
167- assert await try_server ("http://localhost:8000" ) is False
168-
169205 # Mocking httpx.AsyncClient to raise a ConnectTimeout
170206 with patch ("httpx.AsyncClient" ) as mock_client :
171207 mock_client .return_value .__aenter__ .return_value .get .side_effect = (
0 commit comments