Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions cheta/comps/ephem_stk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion cheta/tests/test_comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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