[minor] Strengthen is_connected with cached health probes #22

Merged
brian merged 2 commits from cursor/strengthen-is-connected-health-checks into main 2026-07-05 15:41:01 +02:00
Owner

Summary

Upgrades connection liveness checks so adapters verify backend reachability, not just whether a client object exists.

  • Breaking API changeis_connected is now a method: is_connected() (no longer a @property).
  • TTL-cached health probes — Redis uses ping(); MinIO uses bucket_exists(). Results are cached for 1 second (health_check_ttl_seconds, overridable by subclasses).
  • Cache invalidation — Health cache is cleared on connect() and disconnect().
  • MinIO stale-client handlingconnect() cleans up stale clients before reconnecting.
  • Redis reconnect robustnessconnect() closes an existing client before creating a new one.
  • Tests & docs — Added tests/unit/connection_health_test.py (13 tests); updated integration tests and README.

Test plan

  • pytest tests/unit/connection_health_test.py -v
  • pytest tests/integration/redis_adapter_test.py tests/integration/minio_adapter_test.py tests/integration/connection_aware_interface_test.py -v
  • mypy python_repositories/adapters/ python_repositories/interfaces/connection_aware_interface.py
## Summary Upgrades connection liveness checks so adapters verify backend reachability, not just whether a client object exists. - **Breaking API change** — `is_connected` is now a method: `is_connected()` (no longer a `@property`). - **TTL-cached health probes** — Redis uses `ping()`; MinIO uses `bucket_exists()`. Results are cached for 1 second (`health_check_ttl_seconds`, overridable by subclasses). - **Cache invalidation** — Health cache is cleared on `connect()` and `disconnect()`. - **MinIO stale-client handling** — `connect()` cleans up stale clients before reconnecting. - **Redis reconnect robustness** — `connect()` closes an existing client before creating a new one. - **Tests & docs** — Added `tests/unit/connection_health_test.py` (13 tests); updated integration tests and README. ## Test plan - [x] `pytest tests/unit/connection_health_test.py -v` - [x] `pytest tests/integration/redis_adapter_test.py tests/integration/minio_adapter_test.py tests/integration/connection_aware_interface_test.py -v` - [x] `mypy python_repositories/adapters/ python_repositories/interfaces/connection_aware_interface.py`
brian added 1 commit 2026-07-05 15:31:21 +02:00
Strengthen is_connected with cached health probes.
Code Quality Pipeline / code-quality (pull_request) Failing after 35s
PR Title Check / check-title (pull_request) Successful in 6s
Test Python Package / test (pull_request) Successful in 1m9s
5149299c1b
Convert is_connected to a method that verifies backend liveness via TTL-cached ping (Redis) or bucket_exists (MinIO), with cache invalidation on connect/disconnect.

Co-authored-by: Cursor <[email protected]>
Member

Test Coverage Report:

============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0
rootdir: /workspace/brian/python-repositories
configfile: pyproject.toml
testpaths: tests
plugins: cov-7.1.0, anyio-4.14.1
collected 86 items

tests/integration/connection_aware_interface_test.py ...                 [  3%]
tests/integration/context_aware_interface_test.py ..                     [  5%]
tests/integration/examples_test.py ...                                   [  9%]
tests/integration/json_repository_interface_test.py ....                 [ 13%]
tests/integration/minio_adapter_test.py ............................     [ 46%]
tests/integration/object_repository_interface_test.py ....               [ 51%]
tests/integration/redis_adapter_test.py ......................           [ 76%]
tests/unit/connection_health_test.py .............                       [ 91%]
tests/unit/optional_dependencies_test.py .......                         [100%]

================================ tests coverage ================================
_______________ coverage: platform linux, python 3.12.3-final-0 ________________

Name                                                            Stmts   Miss  Cover   Missing
---------------------------------------------------------------------------------------------
python_repositories/__init__.py                                    11      1    91%   39
python_repositories/adapters/__init__.py                           13      2    85%   37, 42
python_repositories/adapters/minio_adapter.py                     135      1    99%   86
python_repositories/adapters/redis_adapter.py                     111      3    97%   75-77
python_repositories/examples/__init__.py                            0      0   100%
python_repositories/examples/artifact_object_repository.py          9      0   100%
python_repositories/examples/user_json_repository.py               10      0   100%
python_repositories/interfaces/__init__.py                          5      0   100%
python_repositories/interfaces/connection_aware_interface.py        8      0   100%
python_repositories/interfaces/context_aware_interface.py           8      0   100%
python_repositories/interfaces/json_repository_interface.py        10      0   100%
python_repositories/interfaces/object_repository_interface.py      11      0   100%
---------------------------------------------------------------------------------------------
TOTAL                                                             331      7    98%
============================= 86 passed in 30.16s ==============================

**Test Coverage Report:** ``` ============================= test session starts ============================== platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0 rootdir: /workspace/brian/python-repositories configfile: pyproject.toml testpaths: tests plugins: cov-7.1.0, anyio-4.14.1 collected 86 items tests/integration/connection_aware_interface_test.py ... [ 3%] tests/integration/context_aware_interface_test.py .. [ 5%] tests/integration/examples_test.py ... [ 9%] tests/integration/json_repository_interface_test.py .... [ 13%] tests/integration/minio_adapter_test.py ............................ [ 46%] tests/integration/object_repository_interface_test.py .... [ 51%] tests/integration/redis_adapter_test.py ...................... [ 76%] tests/unit/connection_health_test.py ............. [ 91%] tests/unit/optional_dependencies_test.py ....... [100%] ================================ tests coverage ================================ _______________ coverage: platform linux, python 3.12.3-final-0 ________________ Name Stmts Miss Cover Missing --------------------------------------------------------------------------------------------- python_repositories/__init__.py 11 1 91% 39 python_repositories/adapters/__init__.py 13 2 85% 37, 42 python_repositories/adapters/minio_adapter.py 135 1 99% 86 python_repositories/adapters/redis_adapter.py 111 3 97% 75-77 python_repositories/examples/__init__.py 0 0 100% python_repositories/examples/artifact_object_repository.py 9 0 100% python_repositories/examples/user_json_repository.py 10 0 100% python_repositories/interfaces/__init__.py 5 0 100% python_repositories/interfaces/connection_aware_interface.py 8 0 100% python_repositories/interfaces/context_aware_interface.py 8 0 100% python_repositories/interfaces/json_repository_interface.py 10 0 100% python_repositories/interfaces/object_repository_interface.py 11 0 100% --------------------------------------------------------------------------------------------- TOTAL 331 7 98% ============================= 86 passed in 30.16s ============================== ```
brian added 1 commit 2026-07-05 15:38:53 +02:00
Sync uv.lock with pyproject.toml version 0.3.2.
Code Quality Pipeline / code-quality (pull_request) Successful in 31s
PR Title Check / check-title (pull_request) Successful in 6s
Test Python Package / test (pull_request) Successful in 58s
34fc046868
Co-authored-by: Cursor <[email protected]>
Member

Test Coverage Report:

============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0
rootdir: /workspace/brian/python-repositories
configfile: pyproject.toml
testpaths: tests
plugins: cov-7.1.0, anyio-4.14.1
collected 86 items

tests/integration/connection_aware_interface_test.py ...                 [  3%]
tests/integration/context_aware_interface_test.py ..                     [  5%]
tests/integration/examples_test.py ...                                   [  9%]
tests/integration/json_repository_interface_test.py ....                 [ 13%]
tests/integration/minio_adapter_test.py ............................     [ 46%]
tests/integration/object_repository_interface_test.py ....               [ 51%]
tests/integration/redis_adapter_test.py ......................           [ 76%]
tests/unit/connection_health_test.py .............                       [ 91%]
tests/unit/optional_dependencies_test.py .......                         [100%]

================================ tests coverage ================================
_______________ coverage: platform linux, python 3.12.3-final-0 ________________

Name                                                            Stmts   Miss  Cover   Missing
---------------------------------------------------------------------------------------------
python_repositories/__init__.py                                    11      1    91%   39
python_repositories/adapters/__init__.py                           13      2    85%   37, 42
python_repositories/adapters/minio_adapter.py                     135      1    99%   86
python_repositories/adapters/redis_adapter.py                     111      3    97%   75-77
python_repositories/examples/__init__.py                            0      0   100%
python_repositories/examples/artifact_object_repository.py          9      0   100%
python_repositories/examples/user_json_repository.py               10      0   100%
python_repositories/interfaces/__init__.py                          5      0   100%
python_repositories/interfaces/connection_aware_interface.py        8      0   100%
python_repositories/interfaces/context_aware_interface.py           8      0   100%
python_repositories/interfaces/json_repository_interface.py        10      0   100%
python_repositories/interfaces/object_repository_interface.py      11      0   100%
---------------------------------------------------------------------------------------------
TOTAL                                                             331      7    98%
============================= 86 passed in 40.03s ==============================

**Test Coverage Report:** ``` ============================= test session starts ============================== platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0 rootdir: /workspace/brian/python-repositories configfile: pyproject.toml testpaths: tests plugins: cov-7.1.0, anyio-4.14.1 collected 86 items tests/integration/connection_aware_interface_test.py ... [ 3%] tests/integration/context_aware_interface_test.py .. [ 5%] tests/integration/examples_test.py ... [ 9%] tests/integration/json_repository_interface_test.py .... [ 13%] tests/integration/minio_adapter_test.py ............................ [ 46%] tests/integration/object_repository_interface_test.py .... [ 51%] tests/integration/redis_adapter_test.py ...................... [ 76%] tests/unit/connection_health_test.py ............. [ 91%] tests/unit/optional_dependencies_test.py ....... [100%] ================================ tests coverage ================================ _______________ coverage: platform linux, python 3.12.3-final-0 ________________ Name Stmts Miss Cover Missing --------------------------------------------------------------------------------------------- python_repositories/__init__.py 11 1 91% 39 python_repositories/adapters/__init__.py 13 2 85% 37, 42 python_repositories/adapters/minio_adapter.py 135 1 99% 86 python_repositories/adapters/redis_adapter.py 111 3 97% 75-77 python_repositories/examples/__init__.py 0 0 100% python_repositories/examples/artifact_object_repository.py 9 0 100% python_repositories/examples/user_json_repository.py 10 0 100% python_repositories/interfaces/__init__.py 5 0 100% python_repositories/interfaces/connection_aware_interface.py 8 0 100% python_repositories/interfaces/context_aware_interface.py 8 0 100% python_repositories/interfaces/json_repository_interface.py 10 0 100% python_repositories/interfaces/object_repository_interface.py 11 0 100% --------------------------------------------------------------------------------------------- TOTAL 331 7 98% ============================= 86 passed in 40.03s ============================== ```
brian merged commit e7e0fc8c1d into main 2026-07-05 15:41:01 +02:00
brian deleted branch cursor/strengthen-is-connected-health-checks 2026-07-05 15:41:02 +02:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lille-vemmelund/python-repositories#22