From abcbc0d39530707ca336c66f1f14c7ef2b28f943 Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 2 Aug 2024 10:31:52 -0800 Subject: [PATCH] Fixes customized CMR_TIMEOUT, sets timeout to 60 on intersection test --- asf_search/search/search_generator.py | 6 +++--- tests/ASFSearchResults/test_ASFSearchResults.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/asf_search/search/search_generator.py b/asf_search/search/search_generator.py index c7568118..e4bc4b12 100644 --- a/asf_search/search/search_generator.py +++ b/asf_search/search/search_generator.py @@ -185,10 +185,10 @@ def process_page(items: List[ASFProduct], max_results: int, subquery_max_results stop=stop_after_attempt(3), ) def get_page(session: ASFSession, url: str, translated_opts: List) -> Response: - + from asf_search.constants.INTERNAL import CMR_TIMEOUT perf = time.time() try: - response = session.post(url=url, data=translated_opts, timeout=INTERNAL.CMR_TIMEOUT) + response = session.post(url=url, data=translated_opts, timeout=CMR_TIMEOUT) response.raise_for_status() except HTTPError as exc: error_message = f'HTTP {response.status_code}: {response.json()["errors"]}' @@ -197,7 +197,7 @@ def get_page(session: ASFSession, url: str, translated_opts: List) -> Response: if 500 <= response.status_code <= 599: raise ASFSearch5xxError(error_message) from exc except ReadTimeout as exc: - raise ASFSearchError(f'Connection Error (Timeout): CMR took too long to respond. Set asf constant "CMR_TIMEOUT" to increase. ({url=}, timeout={INTERNAL.CMR_TIMEOUT})') from exc + raise ASFSearchError(f'Connection Error (Timeout): CMR took too long to respond. Set asf constant "asf_search.constants.INTERNAL.CMR_TIMEOUT" to increase. ({url=}, timeout={CMR_TIMEOUT})') from exc ASF_LOGGER.warning(f"Query Time Elapsed {time.time() - perf}") return response diff --git a/tests/ASFSearchResults/test_ASFSearchResults.py b/tests/ASFSearchResults/test_ASFSearchResults.py index 7f80a124..397bc051 100644 --- a/tests/ASFSearchResults/test_ASFSearchResults.py +++ b/tests/ASFSearchResults/test_ASFSearchResults.py @@ -18,6 +18,8 @@ from asf_search.constants import PLATFORM import re +from asf_search.exceptions import ASFSearchError + # when this replaces SearchAPI change values to cached API_URL = 'https://api.daac.asf.alaska.edu/services/search/param?' @@ -198,18 +200,21 @@ def run_test_ASFSearchResults_intersection(wkt: str): # exclude SMAP products platforms = [ - PLATFORM.ALOS, PLATFORM.SENTINEL1, - PLATFORM.SIRC, PLATFORM.UAVSAR ] def overlap_check(s1: BaseGeometry, s2: BaseGeometry): return s1.overlaps(s2) or s1.touches(s2) or s2.distance(s1) <= 0.005 - + asf.constants.INTERNAL.CMR_TIMEOUT = 60 for platform in platforms: - results = asf.geo_search(intersectsWith=wkt, platform=platform, maxResults=250) - + try: + results = asf.geo_search(intersectsWith=wkt, platform=platform, maxResults=250) + except ASFSearchError as exc: + asf.constants.INTERNAL.CMR_TIMEOUT = 30 + raise BaseException(f'Failed to perform intersection test with wkt: {wkt}\nplatform: {platform}.\nOriginal exception: {exc}') + + asf.constants.INTERNAL.CMR_TIMEOUT = 30 for product in results: if shape(product.geometry).is_valid: product_geom_wrapped, product_geom_unwrapped, _ = asf.validate_wkt(shape(product.geometry))