Skip to content

Improve retry functionality in a few ways#64

Merged
taldcroft merged 7 commits intomasterfrom
add-mock-func-failure-class
Nov 13, 2025
Merged

Improve retry functionality in a few ways#64
taldcroft merged 7 commits intomasterfrom
add-mock-func-failure-class

Conversation

@taldcroft
Copy link
Member

@taldcroft taldcroft commented Nov 1, 2025

Description

This addresses some shortcomings in the ska_helpers.retry module along with general improvements:

  • Add MockFuncFailure class to help testing retries in other modules.
  • Add retry_func for more convenient wrapping of functions.
  • Update the default tries from -1 (infinite retries) to 3.
  • Define __all__ in a more typical way and use this in the package __init__.py import.
  • Clean up some cruft in the test module (I figured out how to use the pytest caplog).

Interface impacts

Retry defaults are changed, but no code in Ska was using the default since it was useless.

Testing

Unit tests

  • Mac
(ska3) ➜  ska_helpers git:(add-mock-func-failure-class) git rev-parse --short HEAD
92558a6
(ska3) ➜  ska_helpers git:(add-mock-func-failure-class) pytest
========================================== test session starts ==========================================
platform darwin -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/aldcroft/git
configfile: pytest.ini
plugins: anyio-4.7.0, timeout-2.3.1
collected 75 items                                                                                      

ska_helpers/retry/tests/test_retry.py .................                                           [ 22%]
ska_helpers/tests/test_chandra_models.py ..................                                       [ 46%]
ska_helpers/tests/test_docs.py .                                                                  [ 48%]
ska_helpers/tests/test_git_helpers.py s                                                           [ 49%]
ska_helpers/tests/test_paths.py ......                                                            [ 57%]
ska_helpers/tests/test_run_info.py ..                                                             [ 60%]
ska_helpers/tests/test_utils.py ..............................                                    [100%]

===================================== 74 passed, 1 skipped in 5.49s =====================================

Independent check of unit tests by Jean

  • Linux
ska3-jeanconn-kady> pytest
============================= test session starts ==============================
platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /proj/sot/ska/jeanproj/git
configfile: pytest.ini
plugins: anyio-4.7.0, timeout-2.3.1
collected 75 items                                                                                                                    

ska_helpers/retry/tests/test_retry.py .................                                                                         [ 22%]
ska_helpers/tests/test_chandra_models.py ..................                                                                     [ 46%]
ska_helpers/tests/test_docs.py .                                                                                                [ 48%]
ska_helpers/tests/test_git_helpers.py .                                                                                         [ 49%]
ska_helpers/tests/test_paths.py ......                                                                                          [ 57%]
ska_helpers/tests/test_run_info.py ..                                                                                           [ 60%]
ska_helpers/tests/test_utils.py ..............................                                                                  [100%]

========================================================= 75 passed in 14.11s =========================================================
ska3-jeanconn-kady> git rev-parse HEAD
92558a6ceac02f506ead364327a75dc4204b321b

Functional tests

Some functional testing in related testing:

@taldcroft taldcroft changed the title Add MockFuncFailure class to help testing retries in other modules Improve retry functionality in a few ways Nov 13, 2025
@jeanconn
Copy link
Contributor

Looks good to me, though I am wondering if it would save trouble to just update retry and retry_call to also use RETRY_DEFAULTS .

@taldcroft
Copy link
Member Author

taldcroft commented Nov 13, 2025

Looks good to me, though I am wondering if it would save trouble to just update retry and retry_call to also use RETRY_DEFAULTS .

Not sure how much trouble it would save. Certainly this would change some existing behavior in ways that were not intended in the original, e.g. backoff=2 vs default backoff=1 in https://github.com/sot/arc/blob/5a7104495ca530a739c9c32e23a88e420db3dd8d/get_solar_flare_png.py#L27.

@jeanconn
Copy link
Contributor

Yep, I'm only worried for maintainability that there's both the RETRY_DEFAULTS and the defaults that are baked-in to the other/older methods. So really RETRY_DEFAULTS doesn't seem to deserve being a module var. But there isn't that much code in here so I'm not passionate about any change.

Copy link
Contributor

@jeanconn jeanconn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the discussion about defaults.

@taldcroft taldcroft merged commit d916bb8 into master Nov 13, 2025
2 checks passed
@taldcroft taldcroft deleted the add-mock-func-failure-class branch November 13, 2025 20:41
@taldcroft
Copy link
Member Author

Maybe it should be called RETRY_FUNC_DEFAULTS. The one utility of having it was being able to monkeypatch it for testing to make tests run faster.

@taldcroft taldcroft mentioned this pull request Nov 14, 2025
4 tasks
@javierggt javierggt mentioned this pull request Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants