Skip to content

Commit 1923e0c

Browse files
authored
Merge pull request #283 from sot/retry-for-stk-ephemeris
Update ephem_stk code and testing for kadi.occweb built-in retry
2 parents ec57c06 + 2cb5c39 commit 1923e0c

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

cheta/comps/ephem_stk.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from astropy.table import Column, Table
1515
from cxotime import CxoTime, CxoTimeLike
1616
from kadi import occweb
17-
from ska_helpers.retry import retry_call
1817

1918
from .computed_msid import ComputedMsid
2019

@@ -178,14 +177,8 @@ def read_stk_file_from_occweb(path: str | Path, format_out="stk", **kwargs) -> T
178177
Table of ephemeris data.
179178
"""
180179
logger.info(f"Reading OCCweb STK file {path}")
181-
text = retry_call(
182-
occweb.get_occweb_page,
183-
args=[path],
184-
kwargs={"timeout": 10} | kwargs,
185-
tries=3,
186-
backoff=2,
187-
logger=logger,
188-
)
180+
kwargs = {"timeout": 10} | kwargs
181+
text = occweb.get_occweb_page(path, **kwargs)
189182
out = parse_stk_file_text(text, format_out=format_out)
190183
return out
191184

@@ -309,7 +302,7 @@ def get_ephem_stk_paths(
309302
# Then try OCCweb
310303
for dir_path in [EPHEM_STK_RECENT_DIR, EPHEM_STK_ARCHIVE_DIR]:
311304
logger.info(f"Checking OCCweb directory {dir_path}")
312-
files = occweb.get_occweb_dir(dir_path)
305+
files = occweb.get_occweb_dir(dir_path, timeout=5)
313306
files_stk.extend(find_stk_files(files["Name"], dir_path, "occweb", start, stop))
314307
if latest_only and any(f["start"] <= start for f in files_stk):
315308
break

cheta/tests/test_comps.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
import astropy.units as u
1010
import numpy as np
1111
import pytest
12+
import requests
13+
import ska_helpers.retry.api
1214
from cxotime import CxoTime
1315
from Quaternion import Quat
16+
from ska_helpers import retry
1417

1518
from .. import fetch as fetch_cxc
1619
from .. import fetch_eng, fetch_sci
17-
from ..comps import ComputedMsid
20+
from ..comps import ComputedMsid, ephem_stk
1821
from ..comps.ephem_stk import (
1922
EPHEM_STK_DIRS_DEFAULT,
2023
get_ephem_stk_paths,
@@ -626,3 +629,25 @@ def test_dp_roll_css():
626629
)
627630
# fmt: on
628631
assert np.allclose(vals, exp, rtol=0, atol=2e-4)
632+
633+
634+
def test_stk_ephem_timeout(monkeypatch, tmp_path, clear_lru_cache):
635+
monkeypatch.setattr(
636+
ephem_stk, "EPHEM_STK_CACHE_DIR_DEFAULT", str(tmp_path / "cache")
637+
)
638+
mock_requests_get = retry.MockFuncFailure(requests.get, n_fail=1)
639+
monkeypatch.setattr(requests, "get", mock_requests_get)
640+
# Make the test run faster by monkeypatching the default retry delay
641+
monkeypatch.setattr(
642+
ska_helpers.retry.api,
643+
"RETRY_DEFAULTS",
644+
ska_helpers.retry.api.RETRY_DEFAULTS | {"delay": 0.01},
645+
)
646+
647+
result = fetch_cxc.Msid("orbitephem_stk_x", "2023:001", "2023:002")
648+
649+
assert result.MSID == "ORBITEPHEM_STK_X"
650+
# Three places call requests.get (once via get_occweb_dir). Each of those will
651+
# have at least one fail and one success, so >= 6 calls total. There could be a
652+
# bona-fide network failure giving more than 6 calls.
653+
assert len(mock_requests_get.calls) >= 6

0 commit comments

Comments
 (0)