CICD-341 · Redis failure simulation
Encyclopedia · Distributed systems and reliability testing · All snippets
Previous · CICD-340 · Next · CICD-342
1. Where it fits
- Placement isolated compose CI job.
- Prerequisites disposable integration environment, synthetic traffic and controlled test faults.
- Platforms local-linux, github-actions, gitea-actions.
2. Copy the snippet
bash
docker compose stop redis
trap 'docker compose start redis' EXIT
pytest -q tests/test_redis_unavailable.py3. How it works
Stopping the fixture cache forces the application through its unavailable-cache behavior. The EXIT trap restores the service for cleanup on success or failure.
The test fixture loses its cache and restores it on exit.
flowchart TD
N1["Stop disposable Redis"]
N2["Exercise fallback"]
N1 --> N2
N3{"Assertions pass"}
N2 --> N3
N4["Pass result"]
N3 -->|Yes| N4
N5["Fail result"]
N3 -->|No| N5
N6["Restore Redis"]
N4 --> N6
N5 --> N6
4. Verify the result
Use a per-run compose project. The API should exercise the expected cache-miss fallback or service degradation.
Watch for. Confine the test and all synthetic traffic to an authorized, disposable lab. Check cleanup even after a failing assertion.
Validation syntax-validated (Bash parse). Status definitions.