|
9 | 9 | import astropy.units as u |
10 | 10 | import numpy as np |
11 | 11 | import pytest |
| 12 | +import requests |
| 13 | +import ska_helpers.retry.api |
12 | 14 | from cxotime import CxoTime |
13 | 15 | from Quaternion import Quat |
| 16 | +from ska_helpers import retry |
14 | 17 |
|
15 | 18 | from .. import fetch as fetch_cxc |
16 | 19 | from .. import fetch_eng, fetch_sci |
17 | | -from ..comps import ComputedMsid |
| 20 | +from ..comps import ComputedMsid, ephem_stk |
18 | 21 | from ..comps.ephem_stk import ( |
19 | 22 | EPHEM_STK_DIRS_DEFAULT, |
20 | 23 | get_ephem_stk_paths, |
@@ -626,3 +629,25 @@ def test_dp_roll_css(): |
626 | 629 | ) |
627 | 630 | # fmt: on |
628 | 631 | 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