fix(cache): redis backend uses async clients + real-redis CI#731
Merged
Conversation
The redis cache backend was broken against a real server: it maps schemes to the *synchronous* redis.StrictRedis / redis.RedisCluster clients but `_get`/ `_set`/`_delete`/`connect` await them, so `await self.client.get(...)` raised "object ... can't be used in 'await' expression". It only appeared to work because every test mocks the client. * Use the asyncio clients (redis.asyncio.StrictRedis / .RedisCluster), so the awaited calls are real coroutines. Verified end-to-end against a live redis (set/get/delete round-trip). * Close the client on stop (`on_stop` -> `await client.aclose()`); the async client holds real connections. * Bind `redis = None` (not just `aredis`) on ImportError so the "not installed" guard raises ImproperlyConfigured instead of NameError. * mocked_redis fixture: patch redis.asyncio.StrictRedis (the name the backend now uses) and give the mock `aclose`. * Re-enable Test_RedisScheme / the not-installed test, asserting the async client wiring. Add a real-redis CI leg: a `test-redis-integration` job with a redis service container runs new env-gated integration tests (tests/integration/cache) that exercise the backend against a live server -- the coverage the mocks can't give. Advisory (not in the required `check` gate), matching the Kafka job. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #731 +/- ##
==========================================
+ Coverage 94.18% 94.21% +0.02%
==========================================
Files 104 104
Lines 11154 11158 +4
Branches 1202 1203 +1
==========================================
+ Hits 10505 10512 +7
+ Misses 548 545 -3
Partials 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Re-opens #725 onto
master. #725 was merged into its stale stacked-parent branch (claude/fix-715-cibuildwheel-314) instead ofmaster, so its content never reachedmaster. This branch is the same commit cherry-picked directly ontomaster, independent of any chain.Testing redis in CI surfaced that the redis cache backend was broken against a real server. This fixes it and adds the real-redis CI leg.
The bug (proven against a live redis)
The backend maps schemes to the synchronous
redis.StrictRedis/redis.RedisCluster, but_get/_set/_delete/connectawait the client:It only ever looked fine because every unit test mocked the client with
AsyncMock.Fix —
faust/web/cache/backends/redis.pyredis.asyncio.StrictRedis/redis.asyncio.RedisCluster) so the awaited calls are real coroutines. Verified end-to-end against a live redis.on_stop→await client.aclose()).redis = None(not justaredis) onImportError, so the "not installed" guard raisesImproperlyConfiguredinstead ofNameError.Tests & CI
mocked_redisfixture patchesredis.asyncio.StrictRedisand providesaclose.Test_RedisScheme+ the not-installed test re-enabled, asserting the async client wiring.tests/integration/cache/), env-gated onFAUST_TEST_REDIS(skip cleanly when no server is reachable).test-redis-integrationjob with aredis:7service container. Advisory (not in the requiredcheckgate), matching the Kafka integration job.Verification
Unit
test_cache.py(32) + integrationtests/integration/cache(2) → 34 passed; integration tests skip cleanly with no reachable redis; flake8/black/isort clean.🤖 Generated with Claude Code
Generated by Claude Code