Skip to content

fix(cache): redis backend uses async clients + real-redis CI#731

Merged
wbarnha merged 1 commit into
masterfrom
claude/redis-async-client-and-ci
Jul 21, 2026
Merged

fix(cache): redis backend uses async clients + real-redis CI#731
wbarnha merged 1 commit into
masterfrom
claude/redis-async-client-and-ci

Conversation

@wbarnha

@wbarnha wbarnha commented Jul 21, 2026

Copy link
Copy Markdown
Member

Description

Re-opens #725 onto master. #725 was merged into its stale stacked-parent branch (claude/fix-715-cibuildwheel-314) instead of master, so its content never reached master. This branch is the same commit cherry-picked directly onto master, 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/connect await the client:

>>> await app.cache.set("k", b"v", timeout=60)
TypeError: object bool can't be used in 'await' expression

It only ever looked fine because every unit test mocked the client with AsyncMock.

Fix — faust/web/cache/backends/redis.py

  • Use the asyncio clients (redis.asyncio.StrictRedis / redis.asyncio.RedisCluster) so the awaited calls are real coroutines. Verified end-to-end against a live redis.
  • Close the client on stop (on_stopawait client.aclose()).
  • Bind redis = None (not just aredis) on ImportError, so the "not installed" guard raises ImproperlyConfigured instead of NameError.

Tests & CI

  • mocked_redis fixture patches redis.asyncio.StrictRedis and provides aclose.
  • Test_RedisScheme + the not-installed test re-enabled, asserting the async client wiring.
  • New real-redis integration tests (tests/integration/cache/), env-gated on FAUST_TEST_REDIS (skip cleanly when no server is reachable).
  • New test-redis-integration job with a redis:7 service container. Advisory (not in the required check gate), matching the Kafka integration job.

Verification

Unit test_cache.py (32) + integration tests/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

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

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.21%. Comparing base (f77a678) to head (7bde1bd).

Files with missing lines Patch % Lines
faust/web/cache/backends/redis.py 80.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wbarnha
wbarnha added this pull request to the merge queue Jul 21, 2026
Merged via the queue into master with commit 1f0472b Jul 21, 2026
24 of 25 checks passed
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.

1 participant