diff --git a/cheta/comps/ephem_stk.py b/cheta/comps/ephem_stk.py index 63e5abf1..ec0b538c 100644 --- a/cheta/comps/ephem_stk.py +++ b/cheta/comps/ephem_stk.py @@ -14,7 +14,6 @@ from astropy.table import Column, Table from cxotime import CxoTime, CxoTimeLike from kadi import occweb -from ska_helpers.retry import retry_call from .computed_msid import ComputedMsid @@ -178,14 +177,8 @@ def read_stk_file_from_occweb(path: str | Path, format_out="stk", **kwargs) -> T Table of ephemeris data. """ logger.info(f"Reading OCCweb STK file {path}") - text = retry_call( - occweb.get_occweb_page, - args=[path], - kwargs={"timeout": 10} | kwargs, - tries=3, - backoff=2, - logger=logger, - ) + kwargs = {"timeout": 10} | kwargs + text = occweb.get_occweb_page(path, **kwargs) out = parse_stk_file_text(text, format_out=format_out) return out @@ -309,7 +302,7 @@ def get_ephem_stk_paths( # Then try OCCweb for dir_path in [EPHEM_STK_RECENT_DIR, EPHEM_STK_ARCHIVE_DIR]: logger.info(f"Checking OCCweb directory {dir_path}") - files = occweb.get_occweb_dir(dir_path) + files = occweb.get_occweb_dir(dir_path, timeout=5) files_stk.extend(find_stk_files(files["Name"], dir_path, "occweb", start, stop)) if latest_only and any(f["start"] <= start for f in files_stk): break diff --git a/cheta/tests/test_comps.py b/cheta/tests/test_comps.py index bf4c8a9e..4ab036b1 100644 --- a/cheta/tests/test_comps.py +++ b/cheta/tests/test_comps.py @@ -9,12 +9,15 @@ import astropy.units as u import numpy as np import pytest +import requests +import ska_helpers.retry.api from cxotime import CxoTime from Quaternion import Quat +from ska_helpers import retry from .. import fetch as fetch_cxc from .. import fetch_eng, fetch_sci -from ..comps import ComputedMsid +from ..comps import ComputedMsid, ephem_stk from ..comps.ephem_stk import ( EPHEM_STK_DIRS_DEFAULT, get_ephem_stk_paths, @@ -626,3 +629,25 @@ def test_dp_roll_css(): ) # fmt: on assert np.allclose(vals, exp, rtol=0, atol=2e-4) + + +def test_stk_ephem_timeout(monkeypatch, tmp_path, clear_lru_cache): + monkeypatch.setattr( + ephem_stk, "EPHEM_STK_CACHE_DIR_DEFAULT", str(tmp_path / "cache") + ) + mock_requests_get = retry.MockFuncFailure(requests.get, n_fail=1) + monkeypatch.setattr(requests, "get", mock_requests_get) + # Make the test run faster by monkeypatching the default retry delay + monkeypatch.setattr( + ska_helpers.retry.api, + "RETRY_DEFAULTS", + ska_helpers.retry.api.RETRY_DEFAULTS | {"delay": 0.01}, + ) + + result = fetch_cxc.Msid("orbitephem_stk_x", "2023:001", "2023:002") + + assert result.MSID == "ORBITEPHEM_STK_X" + # Three places call requests.get (once via get_occweb_dir). Each of those will + # have at least one fail and one success, so >= 6 calls total. There could be a + # bona-fide network failure giving more than 6 calls. + assert len(mock_requests_get.calls) >= 6