Skip to content

Commit

Permalink
fix(providers): default search timeout to 20s (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunato authored Jan 31, 2025
1 parent e2846dd commit 52a69f6
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions eodag/plugins/search/build_search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from eodag.types import json_field_definition_to_python
from eodag.types.queryables import Queryables, QueryablesDict
from eodag.utils import (
HTTP_REQ_TIMEOUT,
DEFAULT_SEARCH_TIMEOUT,
deepcopy,
dict_items_recursive_sort,
get_geometry_from_various,
Expand Down Expand Up @@ -978,7 +978,7 @@ def _fetch_data(self, url: str) -> Any:
if hasattr(self, "auth") and isinstance(self.auth, AuthBase)
else None
)
timeout = getattr(self.config, "timeout", HTTP_REQ_TIMEOUT)
timeout = getattr(self.config, "timeout", DEFAULT_SEARCH_TIMEOUT)
return fetch_json(url, auth=auth, timeout=timeout)

def normalize_results(
Expand Down
3 changes: 2 additions & 1 deletion eodag/plugins/search/data_request_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
DEFAULT_ITEMS_PER_PAGE,
DEFAULT_MISSION_START_DATE,
DEFAULT_PAGE,
DEFAULT_SEARCH_TIMEOUT,
GENERIC_PRODUCT_TYPE,
HTTP_REQ_TIMEOUT,
USER_AGENT,
Expand Down Expand Up @@ -308,7 +309,7 @@ def query(
request_finished = True

# loop to check search job status
search_timeout = int(getattr(self.config, "timeout", HTTP_REQ_TIMEOUT))
search_timeout = int(getattr(self.config, "timeout", DEFAULT_SEARCH_TIMEOUT))
logger.info(
f"checking status of request job {data_request_id} (timeout={search_timeout}s)"
)
Expand Down
5 changes: 3 additions & 2 deletions eodag/plugins/search/qssearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from eodag.types.search_args import SortByList
from eodag.utils import (
DEFAULT_MISSION_START_DATE,
DEFAULT_SEARCH_TIMEOUT,
GENERIC_PRODUCT_TYPE,
HTTP_REQ_TIMEOUT,
REQ_RETRY_BACKOFF_FACTOR,
Expand Down Expand Up @@ -1190,7 +1191,7 @@ def _request(
info_message = prep.info_message
exception_message = prep.exception_message
try:
timeout = getattr(self.config, "timeout", HTTP_REQ_TIMEOUT)
timeout = getattr(self.config, "timeout", DEFAULT_SEARCH_TIMEOUT)
ssl_verify = getattr(self.config, "ssl_verify", True)

retry_total = getattr(self.config, "retry_total", REQ_RETRY_TOTAL)
Expand Down Expand Up @@ -1753,7 +1754,7 @@ def _request(
raise ValidationError("Cannot request empty URL")
info_message = prep.info_message
exception_message = prep.exception_message
timeout = getattr(self.config, "timeout", HTTP_REQ_TIMEOUT)
timeout = getattr(self.config, "timeout", DEFAULT_SEARCH_TIMEOUT)
ssl_verify = getattr(self.config, "ssl_verify", True)
try:
# auth if needed
Expand Down
1 change: 1 addition & 0 deletions eodag/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
USER_AGENT = {"User-Agent": f"eodag/{eodag_version}"}

HTTP_REQ_TIMEOUT = 5 # in seconds
DEFAULT_SEARCH_TIMEOUT = 20 # in seconds
DEFAULT_STREAM_REQUESTS_TIMEOUT = 60 # in seconds

REQ_RETRY_TOTAL = 3
Expand Down
1 change: 1 addition & 0 deletions tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
DEFAULT_MISSION_START_DATE,
DEFAULT_STREAM_REQUESTS_TIMEOUT,
HTTP_REQ_TIMEOUT,
DEFAULT_SEARCH_TIMEOUT,
USER_AGENT,
get_bucket_name_and_prefix,
get_geometry_from_various,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from jsonpath_ng.jsonpath import Child, Fields, Root

from tests.context import (
HTTP_REQ_TIMEOUT,
DEFAULT_SEARCH_TIMEOUT,
USER_AGENT,
AuthenticationError,
EODataAccessGateway,
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_core_discover_product_types_auth(
],
auth=mock.ANY,
headers=USER_AGENT,
timeout=HTTP_REQ_TIMEOUT,
timeout=DEFAULT_SEARCH_TIMEOUT,
verify=True,
)

Expand Down
15 changes: 9 additions & 6 deletions tests/units/test_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from tests import mock, temporary_environment
from tests.context import (
DEFAULT_ITEMS_PER_PAGE,
HTTP_REQ_TIMEOUT,
DEFAULT_SEARCH_TIMEOUT,
OFFLINE_STATUS,
ONLINE_STATUS,
TEST_RESOURCES_PATH,
Expand Down Expand Up @@ -1296,7 +1296,7 @@ def test_queryables_with_provider(self, mock_requests_get: Mock):
mock_requests_get.assert_called_once_with(
mock.ANY,
url="https://planetarycomputer.microsoft.com/api/stac/v1/search/../queryables",
timeout=HTTP_REQ_TIMEOUT,
timeout=DEFAULT_SEARCH_TIMEOUT,
headers=USER_AGENT,
verify=True,
)
Expand Down Expand Up @@ -1393,7 +1393,10 @@ def run():
self.assertEqual(
norm_planetary_computer_queryables_url, responses.calls[0].request.url
)
self.assertIn(("timeout", 5), responses.calls[0].request.req_kwargs.items())
self.assertIn(
("timeout", DEFAULT_SEARCH_TIMEOUT),
responses.calls[0].request.req_kwargs.items(),
)
self.assertIn(
list(USER_AGENT.items())[0], responses.calls[0].request.headers.items()
)
Expand Down Expand Up @@ -1519,7 +1522,7 @@ def test_product_type_queryables_with_provider(
mock_requests_get.assert_called_once_with(
mock.ANY,
url=planetary_computer_queryables_url,
timeout=HTTP_REQ_TIMEOUT,
timeout=DEFAULT_SEARCH_TIMEOUT,
headers=USER_AGENT,
verify=True,
)
Expand Down Expand Up @@ -1636,7 +1639,7 @@ def test_product_type_queryables_from_constraints(self, mock_requests_get: Mock)
"reanalysis-era5-single-levels/constraints.json",
headers=USER_AGENT,
auth=None,
timeout=5,
timeout=DEFAULT_SEARCH_TIMEOUT,
),
call().raise_for_status(),
call().json(),
Expand All @@ -1646,7 +1649,7 @@ def test_product_type_queryables_from_constraints(self, mock_requests_get: Mock)
"reanalysis-era5-single-levels/form.json",
headers=USER_AGENT,
auth=None,
timeout=5,
timeout=DEFAULT_SEARCH_TIMEOUT,
),
call().raise_for_status(),
call().json(),
Expand Down
7 changes: 4 additions & 3 deletions tests/units/test_search_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from eodag.utils.exceptions import UnsupportedProductType
from tests.context import (
DEFAULT_MISSION_START_DATE,
DEFAULT_SEARCH_TIMEOUT,
HTTP_REQ_TIMEOUT,
NOT_AVAILABLE,
TEST_RESOURCES_PATH,
Expand Down Expand Up @@ -1767,7 +1768,7 @@ def test_plugins_search_buildpostsearchresult_count_and_search(
self.search_plugin.config.api_endpoint,
json=mock.ANY,
headers=USER_AGENT,
timeout=HTTP_REQ_TIMEOUT,
timeout=DEFAULT_SEARCH_TIMEOUT,
auth=self.auth,
verify=True,
)
Expand Down Expand Up @@ -2386,7 +2387,7 @@ def test_plugins_search_ecmwfsearch_discover_queryables(self, mock_requests_get)
"cams-europe-air-quality-reanalyses/constraints.json",
headers=USER_AGENT,
auth=None,
timeout=5,
timeout=DEFAULT_SEARCH_TIMEOUT,
),
call().raise_for_status(),
call().json(),
Expand All @@ -2396,7 +2397,7 @@ def test_plugins_search_ecmwfsearch_discover_queryables(self, mock_requests_get)
"cams-europe-air-quality-reanalyses/form.json",
headers=USER_AGENT,
auth=None,
timeout=5,
timeout=DEFAULT_SEARCH_TIMEOUT,
),
call().raise_for_status(),
call().json(),
Expand Down

0 comments on commit 52a69f6

Please sign in to comment.