mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Add preference for non 404 responses fix test RC.
Fixed race condition with the 404 test.
This commit is contained in:
parent
c302f113b0
commit
5fe7e42d1a
2 changed files with 22 additions and 3 deletions
|
@ -222,6 +222,7 @@ class AsyncParallelTransport(httpx.AsyncBaseTransport):
|
||||||
self,
|
self,
|
||||||
request: httpx.Request,
|
request: httpx.Request,
|
||||||
) -> httpx.Response:
|
) -> httpx.Response:
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
"""Issue parallel requests to all sub-transports.
|
"""Issue parallel requests to all sub-transports.
|
||||||
|
|
||||||
Return the response of the first completed.
|
Return the response of the first completed.
|
||||||
|
@ -254,7 +255,9 @@ class AsyncParallelTransport(httpx.AsyncBaseTransport):
|
||||||
for task in done:
|
for task in done:
|
||||||
try:
|
try:
|
||||||
result = task.result()
|
result = task.result()
|
||||||
if not result.is_error or result.status_code == 404:
|
if not result.is_error:
|
||||||
|
response = result
|
||||||
|
elif result.status_code == 404 and response is None:
|
||||||
response = result
|
response = result
|
||||||
elif not error_response:
|
elif not error_response:
|
||||||
self._logger.warning("Error response: %s for %s", result.status_code, request.url)
|
self._logger.warning("Error response: %s for %s", result.status_code, request.url)
|
||||||
|
|
|
@ -63,9 +63,9 @@ class TestClient(SearxTestCase):
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
'searx.network.client.AsyncProxyTransportFixed.handle_async_request',
|
'searx.network.client.AsyncProxyTransportFixed.handle_async_request',
|
||||||
side_effect=[httpx.Response(404, html="<html/>"), httpx.Response(200, html="<html/>")],
|
side_effect=[httpx.Response(404, html="<html/>"), httpx.Response(404, html="<html/>")],
|
||||||
)
|
)
|
||||||
async def test_parallel_transport_404(self, handler_mock: Mock):
|
async def test_parallel_transport_404_404(self, handler_mock: Mock):
|
||||||
t = client.get_transport(
|
t = client.get_transport(
|
||||||
proxy_urls=["socks5h://local:1080", "socks5h://local:1180"],
|
proxy_urls=["socks5h://local:1080", "socks5h://local:1180"],
|
||||||
proxy_request_redundancy=2,
|
proxy_request_redundancy=2,
|
||||||
|
@ -77,6 +77,22 @@ class TestClient(SearxTestCase):
|
||||||
self.assertEqual(handler_mock.call_count, 2)
|
self.assertEqual(handler_mock.call_count, 2)
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
@patch(
|
||||||
|
'searx.network.client.AsyncProxyTransportFixed.handle_async_request',
|
||||||
|
side_effect=[httpx.Response(200, html="<html/>"), httpx.Response(404, html="<html/>")],
|
||||||
|
)
|
||||||
|
async def test_parallel_transport_404_200(self, handler_mock: Mock):
|
||||||
|
t = client.get_transport(
|
||||||
|
proxy_urls=["socks5h://local:1080", "socks5h://local:1180"],
|
||||||
|
proxy_request_redundancy=2,
|
||||||
|
)
|
||||||
|
self.assertTrue(isinstance(t, client.AsyncParallelTransport))
|
||||||
|
request = httpx.Request(url="http://wiki.com", method="GET")
|
||||||
|
response = await t.handle_async_request(request)
|
||||||
|
handler_mock.assert_called_with(request)
|
||||||
|
self.assertEqual(handler_mock.call_count, 2)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
'searx.network.client.AsyncProxyTransportFixed.handle_async_request',
|
'searx.network.client.AsyncProxyTransportFixed.handle_async_request',
|
||||||
side_effect=[httpx.Response(403, html="<html/>"), httpx.Response(403, html="<html/>")],
|
side_effect=[httpx.Response(403, html="<html/>"), httpx.Response(403, html="<html/>")],
|
||||||
|
|
Loading…
Add table
Reference in a new issue