Skip to content

Rename ResourcePool to ReferenceCountedCache — Closes #151#169

Open
conradbzura wants to merge 3 commits into
wool-labs:mainfrom
conradbzura:151-rename-resourcepool-to-referencecountedcache
Open

Rename ResourcePool to ReferenceCountedCache — Closes #151#169
conradbzura wants to merge 3 commits into
wool-labs:mainfrom
conradbzura:151-rename-resourcepool-to-referencecountedcache

Conversation

@conradbzura

@conradbzura conradbzura commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Rename the internal ResourcePool class to ReferenceCountedCache and its companion Resource class to Reference. Rename the module from resourcepool.py to cache.py. The previous names implied a pre-allocated pool of homogeneous resources (like a connection pool), but the actual abstraction is a lazily-created, keyed, reference-counted cache with TTL-based idle eviction. Similarly, Resource was a single-use acquisition handle rather than a resource in the traditional sense -- Reference better describes its role as a reference-counted handle into the cache. All internal references -- imports, type annotations, variable names, docstrings, and test mocks -- are updated accordingly. No behavioral changes.

Closes #151

Proposed changes

Rename module and classes

Rename src/wool/runtime/resourcepool.py to src/wool/runtime/cache.py, rename the ResourcePool class to ReferenceCountedCache, and rename the Resource class to Reference. The CacheEntry nested dataclass retains its name since it already describes its purpose accurately.

Update all internal references

Update every import, type annotation, variable name, docstring cross-reference, and mock patch target across the codebase to reference the new module path (wool.runtime.cache) and class names (ReferenceCountedCache, Reference). Affected modules span the runtime core (__init__.py), discovery layer (discovery/__init__.py, discovery/local.py, discovery/pool.py), worker layer (worker/connection.py, worker/process.py, worker/service.py), and internal documentation (worker/README.md).

Update test references

Rename tests/runtime/test_resourcepool.py to tests/runtime/test_cache.py. Rename test classes: TestResourcePool to TestReferenceCountedCache and TestResource to TestReference. Update all imports, mock patch targets, dependency markers, and docstring references within the test suite. No test logic is changed.

Test cases

All test changes are mechanical renames with no behavioral modifications. The existing test suite validates the same invariants under the new names.

# Test Suite Given When Then Coverage Target
1 TestReferenceCountedCache A cache with a factory get() is called with a key Returns a Reference instance Acquire semantics
2 TestReferenceCountedCache A cache with active resources Resources are released Reference counts decrement to zero Release semantics
3 TestReferenceCountedCache A cache with unreferenced entries TTL expires Finalizer is called and entry is removed TTL eviction
4 TestReferenceCountedCache A cache with a pending TTL cleanup Resource is reacquired before expiry Cleanup task is cancelled Reacquire cancellation
5 TestReferenceCountedCache A cache with multiple entries clear() is called All entries are finalized Full cleanup
6 TestReferenceCountedCache A cache with multiple entries clear(key) is called Only the targeted entry is finalized Key-specific cleanup
7 TestReferenceCountedCache A cache with varied entry states stats is accessed Accurate counts for total, referenced, and pending entries Statistics accuracy
8 TestReferenceCountedCache A cache used as async context manager Context is exited All resources are cleared Context manager lifecycle
9 TestReferenceCountedCache A cache under concurrent access Multiple tasks acquire and release Pool invariants hold and no resources leak Concurrency safety
10 TestReference A Reference from a cache Used as async context manager Acquires on enter, releases on exit Context manager protocol
11 TestReference A Reference that has already been entered Entered a second time Raises RuntimeError Acquire-once enforcement
12 TestReference A Reference from a pool that fails during acquire Entering the context manager Raises the underlying error and does not mark as acquired Acquire failure handling
13 TestReference A Reference that was never acquired Attempting to exit context Raises RuntimeError Release-without-acquire guard
14 TestReference A Reference that was already released Attempting to exit context again Raises RuntimeError Double-release guard
15 TestSubscriberMeta No subscriber pool in ContextVar A subscriber is constructed A ReferenceCountedCache is set in the ContextVar Auto-pool initialization

@conradbzura conradbzura force-pushed the 151-rename-resourcepool-to-referencecountedcache branch from 63b7f3d to c256550 Compare April 7, 2026 03:10
@conradbzura conradbzura self-assigned this Apr 7, 2026
The class name now accurately describes the data structure's behavior:
a reference-counted cache with TTL-based cleanup, not a generic
resource pool. The module is also renamed from resourcepool.py to
cache.py to match.

Closes wool-labs#151
@conradbzura conradbzura marked this pull request as ready for review April 7, 2026 17:35
@conradbzura conradbzura force-pushed the 151-rename-resourcepool-to-referencecountedcache branch from c256550 to c1bfe94 Compare April 7, 2026 17:59
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.

Rename ResourcePool to ReferenceCountedCache

1 participant