[patch] Extract shared connection lifecycle into ConnectionAwareAdapter #23

Merged
brian merged 2 commits from cursor/extract-connection-aware-adapter into main 2026-07-05 16:15:35 +02:00
Owner

Summary

  • Add internal ConnectionAwareAdapter base class with shared context-manager behavior, TTL-cached is_connected(), and _require_connected() helper
  • Refactor RedisAdapter and MinioAdapter to inherit from the base class, removing ~70 lines of duplicated connection/health-check logic
  • Update connection health unit tests to patch time.monotonic in the base module
  • Sync uv.lock with pyproject.toml version 0.4.0

Test plan

  • uv run pytest tests/unit/connection_health_test.py tests/integration/
  • Verify pre-commit / CI passes on the PR
## Summary - Add internal `ConnectionAwareAdapter` base class with shared context-manager behavior, TTL-cached `is_connected()`, and `_require_connected()` helper - Refactor `RedisAdapter` and `MinioAdapter` to inherit from the base class, removing ~70 lines of duplicated connection/health-check logic - Update connection health unit tests to patch `time.monotonic` in the base module - Sync `uv.lock` with `pyproject.toml` version 0.4.0 ## Test plan - [x] `uv run pytest tests/unit/connection_health_test.py tests/integration/` - [ ] Verify pre-commit / CI passes on the PR
brian added 2 commits 2026-07-05 16:13:51 +02:00
Move duplicated context-manager, health-check cache, and connection guards from Redis and Minio adapters into an internal base class.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sync uv.lock with pyproject.toml version 0.4.0.
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 48s
b5a92e6222
Co-authored-by: Cursor <cursoragent@cursor.com>
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/connection_aware_adapter.py           45      0   100%
python_repositories/adapters/minio_adapter.py                     104      1    99%   55
python_repositories/adapters/redis_adapter.py                      81      3    96%   44-46
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                                                             315      7    98%
============================= 86 passed in 30.19s ==============================

**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/connection_aware_adapter.py 45 0 100% python_repositories/adapters/minio_adapter.py 104 1 99% 55 python_repositories/adapters/redis_adapter.py 81 3 96% 44-46 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 315 7 98% ============================= 86 passed in 30.19s ============================== ```
brian merged commit 7b4cf8421b into main 2026-07-05 16:15:35 +02:00
brian deleted branch cursor/extract-connection-aware-adapter 2026-07-05 16:15:36 +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#23